home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / lib / gdbus-2.0 / codegen / codegen.py < prev    next >
Text File  |  2014-12-31  |  188KB  |  3,374 lines

  1. # -*- Mode: Python -*-
  2.  
  3. # GDBus - GLib D-Bus Library
  4. #
  5. # Copyright (C) 2008-2011 Red Hat, Inc.
  6. #
  7. # This library is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU Lesser General Public
  9. # License as published by the Free Software Foundation; either
  10. # version 2 of the License, or (at your option) any later version.
  11. #
  12. # This library is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. # Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General
  18. # Public License along with this library; if not, write to the
  19. # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  20. # Boston, MA 02111-1307, USA.
  21. #
  22. # Author: David Zeuthen <davidz@redhat.com>
  23.  
  24. import sys
  25.  
  26. from . import config
  27. from . import utils
  28. from . import dbustypes
  29.  
  30. # ----------------------------------------------------------------------------------------------------
  31.  
  32. class CodeGenerator:
  33.     def __init__(self, ifaces, namespace, interface_prefix, generate_objmanager, docbook_gen, h, c):
  34.         self.docbook_gen = docbook_gen
  35.         self.generate_objmanager = generate_objmanager
  36.         self.ifaces = ifaces
  37.         self.h = h
  38.         self.c = c
  39.         self.namespace = namespace
  40.         if len(namespace) > 0:
  41.             if utils.is_ugly_case(namespace):
  42.                 self.namespace = namespace.replace('_', '')
  43.                 self.ns_upper = namespace.upper() + '_'
  44.                 self.ns_lower = namespace.lower() + '_'
  45.             else:
  46.                 self.ns_upper = utils.camel_case_to_uscore(namespace).upper() + '_'
  47.                 self.ns_lower = utils.camel_case_to_uscore(namespace).lower() + '_'
  48.         else:
  49.             self.ns_upper = ''
  50.             self.ns_lower = ''
  51.         self.interface_prefix = interface_prefix
  52.         self.header_guard = self.h.name.upper().replace('.', '_').replace('-', '_').replace('/', '_')
  53.  
  54.     # ----------------------------------------------------------------------------------------------------
  55.  
  56.     def generate_intro(self):
  57.         self.c.write('/*\n'
  58.                      ' * Generated by gdbus-codegen %s. DO NOT EDIT.\n'
  59.                      ' *\n'
  60.                      ' * The license of this code is the same as for the source it was derived from.\n'
  61.                      ' */\n'
  62.                      '\n'
  63.                      %(config.VERSION))
  64.         self.c.write('#ifdef HAVE_CONFIG_H\n'
  65.                      '#  include "config.h"\n'
  66.                      '#endif\n'
  67.                      '\n'
  68.                      '#include "%s"\n'
  69.                      '\n'
  70.                      '#include <string.h>\n'
  71.                      %(self.h.name))
  72.  
  73.         self.c.write('#ifdef G_OS_UNIX\n'
  74.                      '#  include <gio/gunixfdlist.h>\n'
  75.                      '#endif\n'
  76.                      '\n')
  77.  
  78.         self.c.write('typedef struct\n'
  79.                      '{\n'
  80.                      '  GDBusArgInfo parent_struct;\n'
  81.                      '  gboolean use_gvariant;\n'
  82.                      '} _ExtendedGDBusArgInfo;\n'
  83.                      '\n')
  84.  
  85.         self.c.write('typedef struct\n'
  86.                      '{\n'
  87.                      '  GDBusMethodInfo parent_struct;\n'
  88.                      '  const gchar *signal_name;\n'
  89.                      '  gboolean pass_fdlist;\n'
  90.                      '} _ExtendedGDBusMethodInfo;\n'
  91.                      '\n')
  92.  
  93.         self.c.write('typedef struct\n'
  94.                      '{\n'
  95.                      '  GDBusSignalInfo parent_struct;\n'
  96.                      '  const gchar *signal_name;\n'
  97.                      '} _ExtendedGDBusSignalInfo;\n'
  98.                      '\n')
  99.  
  100.         self.c.write('typedef struct\n'
  101.                      '{\n'
  102.                      '  GDBusPropertyInfo parent_struct;\n'
  103.                      '  const gchar *hyphen_name;\n'
  104.                      '  gboolean use_gvariant;\n'
  105.                      '} _ExtendedGDBusPropertyInfo;\n'
  106.                      '\n')
  107.  
  108.         self.c.write('typedef struct\n'
  109.                      '{\n'
  110.                      '  GDBusInterfaceInfo parent_struct;\n'
  111.                      '  const gchar *hyphen_name;\n'
  112.                      '} _ExtendedGDBusInterfaceInfo;\n'
  113.                      '\n')
  114.  
  115.         self.c.write('typedef struct\n'
  116.                      '{\n'
  117.                      '  const _ExtendedGDBusPropertyInfo *info;\n'
  118.                      '  guint prop_id;\n'
  119.                      '  GValue orig_value; /* the value before the change */\n'
  120.                      '} ChangedProperty;\n'
  121.                      '\n'
  122.                      'static void\n'
  123.                      '_changed_property_free (ChangedProperty *data)\n'
  124.                      '{\n'
  125.                      '  g_value_unset (&data->orig_value);\n'
  126.                      '  g_free (data);\n'
  127.                      '}\n'
  128.                      '\n')
  129.  
  130.         self.c.write('static gboolean\n'
  131.                      '_g_strv_equal0 (gchar **a, gchar **b)\n'
  132.                      '{\n'
  133.                      '  gboolean ret = FALSE;\n'
  134.                      '  guint n;\n'
  135.                      '  if (a == NULL && b == NULL)\n'
  136.                      '    {\n'
  137.                      '      ret = TRUE;\n'
  138.                      '      goto out;\n'
  139.                      '    }\n'
  140.                      '  if (a == NULL || b == NULL)\n'
  141.                      '    goto out;\n'
  142.                      '  if (g_strv_length (a) != g_strv_length (b))\n'
  143.                      '    goto out;\n'
  144.                      '  for (n = 0; a[n] != NULL; n++)\n'
  145.                      '    if (g_strcmp0 (a[n], b[n]) != 0)\n'
  146.                      '      goto out;\n'
  147.                      '  ret = TRUE;\n'
  148.                      'out:\n'
  149.                      '  return ret;\n'
  150.                      '}\n'
  151.                      '\n')
  152.  
  153.         self.c.write('static gboolean\n'
  154.                      '_g_variant_equal0 (GVariant *a, GVariant *b)\n'
  155.                      '{\n'
  156.                      '  gboolean ret = FALSE;\n'
  157.                      '  if (a == NULL && b == NULL)\n'
  158.                      '    {\n'
  159.                      '      ret = TRUE;\n'
  160.                      '      goto out;\n'
  161.                      '    }\n'
  162.                      '  if (a == NULL || b == NULL)\n'
  163.                      '    goto out;\n'
  164.                      '  ret = g_variant_equal (a, b);\n'
  165.                      'out:\n'
  166.                      '  return ret;\n'
  167.                      '}\n'
  168.                      '\n')
  169.  
  170.         # simplified - only supports the types we use
  171.         self.c.write('G_GNUC_UNUSED static gboolean\n'
  172.                      '_g_value_equal (const GValue *a, const GValue *b)\n'
  173.                      '{\n'
  174.                      '  gboolean ret = FALSE;\n'
  175.                      '  g_assert (G_VALUE_TYPE (a) == G_VALUE_TYPE (b));\n'
  176.                      '  switch (G_VALUE_TYPE (a))\n'
  177.                      '    {\n'
  178.                      '      case G_TYPE_BOOLEAN:\n'
  179.                      '        ret = (g_value_get_boolean (a) == g_value_get_boolean (b));\n'
  180.                      '        break;\n'
  181.                      '      case G_TYPE_UCHAR:\n'
  182.                      '        ret = (g_value_get_uchar (a) == g_value_get_uchar (b));\n'
  183.                      '        break;\n'
  184.                      '      case G_TYPE_INT:\n'
  185.                      '        ret = (g_value_get_int (a) == g_value_get_int (b));\n'
  186.                      '        break;\n'
  187.                      '      case G_TYPE_UINT:\n'
  188.                      '        ret = (g_value_get_uint (a) == g_value_get_uint (b));\n'
  189.                      '        break;\n'
  190.                      '      case G_TYPE_INT64:\n'
  191.                      '        ret = (g_value_get_int64 (a) == g_value_get_int64 (b));\n'
  192.                      '        break;\n'
  193.                      '      case G_TYPE_UINT64:\n'
  194.                      '        ret = (g_value_get_uint64 (a) == g_value_get_uint64 (b));\n'
  195.                      '        break;\n'
  196.                      '      case G_TYPE_DOUBLE:\n'
  197.                      '        {\n'
  198.                      '          /* Avoid -Wfloat-equal warnings by doing a direct bit compare */\n'
  199.                      '          gdouble da = g_value_get_double (a);\n'
  200.                      '          gdouble db = g_value_get_double (b);\n'
  201.                      '          ret = memcmp (&da, &db, sizeof (gdouble)) == 0;\n'
  202.                      '        }\n'
  203.                      '        break;\n'
  204.                      '      case G_TYPE_STRING:\n'
  205.                      '        ret = (g_strcmp0 (g_value_get_string (a), g_value_get_string (b)) == 0);\n'
  206.                      '        break;\n'
  207.                      '      case G_TYPE_VARIANT:\n'
  208.                      '        ret = _g_variant_equal0 (g_value_get_variant (a), g_value_get_variant (b));\n'
  209.                      '        break;\n'
  210.                      '      default:\n'
  211.                      '        if (G_VALUE_TYPE (a) == G_TYPE_STRV)\n'
  212.                      '          ret = _g_strv_equal0 (g_value_get_boxed (a), g_value_get_boxed (b));\n'
  213.                      '        else\n'
  214.                      '          g_critical ("_g_value_equal() does not handle type %s", g_type_name (G_VALUE_TYPE (a)));\n'
  215.                      '        break;\n'
  216.                      '    }\n'
  217.                      '  return ret;\n'
  218.                      '}\n'
  219.                      '\n')
  220.  
  221.         self.h.write('/*\n'
  222.                      ' * Generated by gdbus-codegen %s. DO NOT EDIT.\n'
  223.                      ' *\n'
  224.                      ' * The license of this code is the same as for the source it was derived from.\n'
  225.                      ' */\n'
  226.                      '\n'
  227.                      '#ifndef __%s__\n'
  228.                      '#define __%s__\n'
  229.                      '\n'%(config.VERSION, self.header_guard, self.header_guard))
  230.         self.h.write('#include <gio/gio.h>\n'
  231.                      '\n'
  232.                      'G_BEGIN_DECLS\n'
  233.                      '\n')
  234.  
  235.     # ----------------------------------------------------------------------------------------------------
  236.  
  237.     def declare_types(self):
  238.         for i in self.ifaces:
  239.             self.h.write('\n')
  240.             self.h.write('/* ------------------------------------------------------------------------ */\n')
  241.             self.h.write('/* Declarations for %s */\n'%i.name)
  242.             self.h.write('\n')
  243.  
  244.             # First the GInterface
  245.             self.h.write('#define %sTYPE_%s (%s_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
  246.             self.h.write('#define %s%s(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_%s, %s))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
  247.             self.h.write('#define %sIS_%s(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_%s))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
  248.             self.h.write('#define %s%s_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), %sTYPE_%s, %sIface))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
  249.             self.h.write('\n')
  250.             self.h.write('struct _%s;\n'%(i.camel_name))
  251.             self.h.write('typedef struct _%s %s;\n'%(i.camel_name, i.camel_name))
  252.             self.h.write('typedef struct _%sIface %sIface;\n'%(i.camel_name, i.camel_name))
  253.             self.h.write('\n')
  254.             self.h.write('struct _%sIface\n'%(i.camel_name))
  255.             self.h.write('{\n')
  256.             self.h.write('  GTypeInterface parent_iface;\n')
  257.  
  258.             function_pointers = {}
  259.  
  260.             # vfuncs for methods
  261.             if len(i.methods) > 0:
  262.                 self.h.write('\n')
  263.                 for m in i.methods:
  264.                     unix_fd = False
  265.                     if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
  266.                         unix_fd = True
  267.                     key = (m.since, '_method_%s'%m.name_lower)
  268.                     value  = '  gboolean (*handle_%s) (\n'%(m.name_lower)
  269.                     value += '    %s *object,\n'%(i.camel_name)
  270.                     value += '    GDBusMethodInvocation *invocation'%()
  271.                     if unix_fd:
  272.                         value += ',\n    GUnixFDList *fd_list'
  273.                     for a in m.in_args:
  274.                         value += ',\n    %sarg_%s'%(a.ctype_in, a.name)
  275.                     value += ');\n\n'
  276.                     function_pointers[key] = value
  277.  
  278.             # vfuncs for signals
  279.             if len(i.signals) > 0:
  280.                 self.h.write('\n')
  281.                 for s in i.signals:
  282.                     key = (s.since, '_signal_%s'%s.name_lower)
  283.                     value  = '  void (*%s) (\n'%(s.name_lower)
  284.                     value += '    %s *object'%(i.camel_name)
  285.                     for a in s.args:
  286.                         value += ',\n    %sarg_%s'%(a.ctype_in, a.name)
  287.                     value += ');\n\n'
  288.                     function_pointers[key] = value
  289.  
  290.             # vfuncs for properties
  291.             if len(i.properties) > 0:
  292.                 self.h.write('\n')
  293.                 for p in i.properties:
  294.                     key = (p.since, '_prop_get_%s'%p.name_lower)
  295.                     value = '  %s (*get_%s) (%s *object);\n\n'%(p.arg.ctype_in, p.name_lower, i.camel_name)
  296.                     function_pointers[key] = value
  297.  
  298.             # Sort according to @since tag, then name.. this ensures
  299.             # that the function pointers don't change order assuming
  300.             # judicious use of @since
  301.             #
  302.             # Also use a proper version comparison function so e.g.
  303.             # 10.0 comes after 2.0.
  304.             #
  305.             # See https://bugzilla.gnome.org/show_bug.cgi?id=647577#c5
  306.             # for discussion
  307.             for key in sorted(function_pointers.keys(), key=utils.version_cmp_key):
  308.                 self.h.write('%s'%function_pointers[key])
  309.  
  310.             self.h.write('};\n')
  311.             self.h.write('\n')
  312.             self.h.write('GType %s_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
  313.             self.h.write('\n')
  314.             self.h.write('GDBusInterfaceInfo *%s_interface_info (void);\n'%(i.name_lower))
  315.             self.h.write('guint %s_override_properties (GObjectClass *klass, guint property_id_begin);\n'%(i.name_lower))
  316.             self.h.write('\n')
  317.  
  318.             # Then method call completion functions
  319.             if len(i.methods) > 0:
  320.                 self.h.write('\n')
  321.                 self.h.write('/* D-Bus method call completion functions: */\n')
  322.                 for m in i.methods:
  323.                     unix_fd = False
  324.                     if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
  325.                         unix_fd = True
  326.                     if m.deprecated:
  327.                         self.h.write('G_GNUC_DEPRECATED ')
  328.                     self.h.write('void %s_complete_%s (\n'
  329.                                  '    %s *object,\n'
  330.                                  '    GDBusMethodInvocation *invocation'%(i.name_lower, m.name_lower, i.camel_name))
  331.                     if unix_fd:
  332.                         self.h.write(',\n    GUnixFDList *fd_list')
  333.                     for a in m.out_args:
  334.                         self.h.write(',\n    %s%s'%(a.ctype_in, a.name))
  335.                     self.h.write(');\n')
  336.                     self.h.write('\n')
  337.                 self.h.write('\n')
  338.  
  339.             # Then signal emission functions
  340.             if len(i.signals) > 0:
  341.                 self.h.write('\n')
  342.                 self.h.write('/* D-Bus signal emissions functions: */\n')
  343.                 for s in i.signals:
  344.                     if s.deprecated:
  345.                         self.h.write('G_GNUC_DEPRECATED ')
  346.                     self.h.write('void %s_emit_%s (\n'
  347.                                  '    %s *object'%(i.name_lower, s.name_lower, i.camel_name))
  348.                     for a in s.args:
  349.                         self.h.write(',\n    %sarg_%s'%(a.ctype_in, a.name))
  350.                     self.h.write(');\n')
  351.                     self.h.write('\n')
  352.                 self.h.write('\n')
  353.  
  354.             # Then method call declarations
  355.             if len(i.methods) > 0:
  356.                 self.h.write('\n')
  357.                 self.h.write('/* D-Bus method calls: */\n')
  358.                 for m in i.methods:
  359.                     unix_fd = False
  360.                     if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
  361.                         unix_fd = True
  362.                     # async begin
  363.                     if m.deprecated:
  364.                         self.h.write('G_GNUC_DEPRECATED ')
  365.                     self.h.write('void %s_call_%s (\n'
  366.                                  '    %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
  367.                     for a in m.in_args:
  368.                         self.h.write(',\n    %sarg_%s'%(a.ctype_in, a.name))
  369.                     if unix_fd:
  370.                         self.h.write(',\n    GUnixFDList *fd_list')
  371.                     self.h.write(',\n'
  372.                                  '    GCancellable *cancellable,\n'
  373.                                  '    GAsyncReadyCallback callback,\n'
  374.                                  '    gpointer user_data);\n')
  375.                     self.h.write('\n')
  376.                     # async finish
  377.                     if m.deprecated:
  378.                         self.h.write('G_GNUC_DEPRECATED ')
  379.                     self.h.write('gboolean %s_call_%s_finish (\n'
  380.                                  '    %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
  381.                     for a in m.out_args:
  382.                         self.h.write(',\n    %sout_%s'%(a.ctype_out, a.name))
  383.                     if unix_fd:
  384.                         self.h.write(',\n    GUnixFDList **out_fd_list')
  385.                     self.h.write(',\n'
  386.                                  '    GAsyncResult *res,\n'
  387.                                  '    GError **error);\n')
  388.                     self.h.write('\n')
  389.                     # sync
  390.                     if m.deprecated:
  391.                         self.h.write('G_GNUC_DEPRECATED ')
  392.                     self.h.write('gboolean %s_call_%s_sync (\n'
  393.                                  '    %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
  394.                     for a in m.in_args:
  395.                         self.h.write(',\n    %sarg_%s'%(a.ctype_in, a.name))
  396.                     if unix_fd:
  397.                         self.h.write(',\n    GUnixFDList  *fd_list')
  398.                     for a in m.out_args:
  399.                         self.h.write(',\n    %sout_%s'%(a.ctype_out, a.name))
  400.                     if unix_fd:
  401.                         self.h.write(',\n    GUnixFDList **out_fd_list')
  402.                     self.h.write(',\n'
  403.                                  '    GCancellable *cancellable,\n'
  404.                                  '    GError **error);\n')
  405.                     self.h.write('\n')
  406.                 self.h.write('\n')
  407.  
  408.             # Then the property accessor declarations
  409.             if len(i.properties) > 0:
  410.                 self.h.write('\n')
  411.                 self.h.write('/* D-Bus property accessors: */\n')
  412.                 for p in i.properties:
  413.                     # getter
  414.                     if p.deprecated:
  415.                         self.h.write('G_GNUC_DEPRECATED ')
  416.                     self.h.write('%s%s_get_%s (%s *object);\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
  417.                     if p.arg.free_func != None:
  418.                         if p.deprecated:
  419.                             self.h.write('G_GNUC_DEPRECATED ')
  420.                         self.h.write('%s%s_dup_%s (%s *object);\n'%(p.arg.ctype_in_dup, i.name_lower, p.name_lower, i.camel_name))
  421.                     # setter
  422.                     if p.deprecated:
  423.                         self.h.write('G_GNUC_DEPRECATED ')
  424.                     self.h.write('void %s_set_%s (%s *object, %svalue);\n'%(i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in, ))
  425.                     self.h.write('\n')
  426.  
  427.             # Then the proxy
  428.             self.h.write('\n')
  429.             self.h.write('/* ---- */\n')
  430.             self.h.write('\n')
  431.             self.h.write('#define %sTYPE_%s_PROXY (%s_proxy_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
  432.             self.h.write('#define %s%s_PROXY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_%s_PROXY, %sProxy))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
  433.             self.h.write('#define %s%s_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), %sTYPE_%s_PROXY, %sProxyClass))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
  434.             self.h.write('#define %s%s_PROXY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), %sTYPE_%s_PROXY, %sProxyClass))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
  435.             self.h.write('#define %sIS_%s_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_%s_PROXY))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
  436.             self.h.write('#define %sIS_%s_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), %sTYPE_%s_PROXY))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
  437.             self.h.write('\n')
  438.             self.h.write('typedef struct _%sProxy %sProxy;\n'%(i.camel_name, i.camel_name))
  439.             self.h.write('typedef struct _%sProxyClass %sProxyClass;\n'%(i.camel_name, i.camel_name))
  440.             self.h.write('typedef struct _%sProxyPrivate %sProxyPrivate;\n'%(i.camel_name, i.camel_name))
  441.             self.h.write('\n')
  442.             self.h.write('struct _%sProxy\n'%(i.camel_name))
  443.             self.h.write('{\n')
  444.             self.h.write('  /*< private >*/\n')
  445.             self.h.write('  GDBusProxy parent_instance;\n')
  446.             self.h.write('  %sProxyPrivate *priv;\n'%(i.camel_name))
  447.             self.h.write('};\n')
  448.             self.h.write('\n')
  449.             self.h.write('struct _%sProxyClass\n'%(i.camel_name))
  450.             self.h.write('{\n')
  451.             self.h.write('  GDBusProxyClass parent_class;\n')
  452.             self.h.write('};\n')
  453.             self.h.write('\n')
  454.             self.h.write('GType %s_proxy_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
  455.  
  456.             self.h.write('\n')
  457.             if i.deprecated:
  458.                 self.h.write('G_GNUC_DEPRECATED ')
  459.             self.h.write('void %s_proxy_new (\n'
  460.                          '    GDBusConnection     *connection,\n'
  461.                          '    GDBusProxyFlags      flags,\n'
  462.                          '    const gchar         *name,\n'
  463.                          '    const gchar         *object_path,\n'
  464.                          '    GCancellable        *cancellable,\n'
  465.                          '    GAsyncReadyCallback  callback,\n'
  466.                          '    gpointer             user_data);\n'
  467.                          %(i.name_lower))
  468.             if i.deprecated:
  469.                 self.h.write('G_GNUC_DEPRECATED ')
  470.             self.h.write('%s *%s_proxy_new_finish (\n'
  471.                          '    GAsyncResult        *res,\n'
  472.                          '    GError             **error);\n'
  473.                          %(i.camel_name, i.name_lower))
  474.             if i.deprecated:
  475.                 self.h.write('G_GNUC_DEPRECATED ')
  476.             self.h.write('%s *%s_proxy_new_sync (\n'
  477.                          '    GDBusConnection     *connection,\n'
  478.                          '    GDBusProxyFlags      flags,\n'
  479.                          '    const gchar         *name,\n'
  480.                          '    const gchar         *object_path,\n'
  481.                          '    GCancellable        *cancellable,\n'
  482.                          '    GError             **error);\n'
  483.                          %(i.camel_name, i.name_lower))
  484.             self.h.write('\n')
  485.             if i.deprecated:
  486.                 self.h.write('G_GNUC_DEPRECATED ')
  487.             self.h.write('void %s_proxy_new_for_bus (\n'
  488.                          '    GBusType             bus_type,\n'
  489.                          '    GDBusProxyFlags      flags,\n'
  490.                          '    const gchar         *name,\n'
  491.                          '    const gchar         *object_path,\n'
  492.                          '    GCancellable        *cancellable,\n'
  493.                          '    GAsyncReadyCallback  callback,\n'
  494.                          '    gpointer             user_data);\n'
  495.                          %(i.name_lower))
  496.             if i.deprecated:
  497.                 self.h.write('G_GNUC_DEPRECATED ')
  498.             self.h.write('%s *%s_proxy_new_for_bus_finish (\n'
  499.                          '    GAsyncResult        *res,\n'
  500.                          '    GError             **error);\n'
  501.                          %(i.camel_name, i.name_lower))
  502.             if i.deprecated:
  503.                 self.h.write('G_GNUC_DEPRECATED ')
  504.             self.h.write('%s *%s_proxy_new_for_bus_sync (\n'
  505.                          '    GBusType             bus_type,\n'
  506.                          '    GDBusProxyFlags      flags,\n'
  507.                          '    const gchar         *name,\n'
  508.                          '    const gchar         *object_path,\n'
  509.                          '    GCancellable        *cancellable,\n'
  510.                          '    GError             **error);\n'
  511.                          %(i.camel_name, i.name_lower))
  512.             self.h.write('\n')
  513.  
  514.             # Then the skeleton
  515.             self.h.write('\n')
  516.             self.h.write('/* ---- */\n')
  517.             self.h.write('\n')
  518.             self.h.write('#define %sTYPE_%s_SKELETON (%s_skeleton_get_type ())\n'%(i.ns_upper, i.name_upper, i.name_lower))
  519.             self.h.write('#define %s%s_SKELETON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_%s_SKELETON, %sSkeleton))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
  520.             self.h.write('#define %s%s_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), %sTYPE_%s_SKELETON, %sSkeletonClass))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
  521.             self.h.write('#define %s%s_SKELETON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), %sTYPE_%s_SKELETON, %sSkeletonClass))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper, i.camel_name))
  522.             self.h.write('#define %sIS_%s_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_%s_SKELETON))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
  523.             self.h.write('#define %sIS_%s_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), %sTYPE_%s_SKELETON))\n'%(i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
  524.             self.h.write('\n')
  525.             self.h.write('typedef struct _%sSkeleton %sSkeleton;\n'%(i.camel_name, i.camel_name))
  526.             self.h.write('typedef struct _%sSkeletonClass %sSkeletonClass;\n'%(i.camel_name, i.camel_name))
  527.             self.h.write('typedef struct _%sSkeletonPrivate %sSkeletonPrivate;\n'%(i.camel_name, i.camel_name))
  528.             self.h.write('\n')
  529.             self.h.write('struct _%sSkeleton\n'%(i.camel_name))
  530.             self.h.write('{\n')
  531.             self.h.write('  /*< private >*/\n')
  532.             self.h.write('  GDBusInterfaceSkeleton parent_instance;\n')
  533.             self.h.write('  %sSkeletonPrivate *priv;\n'%(i.camel_name))
  534.             self.h.write('};\n')
  535.             self.h.write('\n')
  536.             self.h.write('struct _%sSkeletonClass\n'%(i.camel_name))
  537.             self.h.write('{\n')
  538.             self.h.write('  GDBusInterfaceSkeletonClass parent_class;\n')
  539.             self.h.write('};\n')
  540.             self.h.write('\n')
  541.             self.h.write('GType %s_skeleton_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
  542.             self.h.write('\n')
  543.             if i.deprecated:
  544.                 self.h.write('G_GNUC_DEPRECATED ')
  545.             self.h.write('%s *%s_skeleton_new (void);\n'%(i.camel_name, i.name_lower))
  546.  
  547.             self.h.write('\n')
  548.  
  549.         # Finally, the Object, ObjectProxy, ObjectSkeleton and ObjectManagerClient
  550.         if self.generate_objmanager:
  551.             self.h.write('\n')
  552.             self.h.write('/* ---- */\n')
  553.             self.h.write('\n')
  554.             self.h.write('#define %sTYPE_OBJECT (%sobject_get_type ())\n'%(self.ns_upper, self.ns_lower))
  555.             self.h.write('#define %sOBJECT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_OBJECT, %sObject))\n'%(self.ns_upper, self.ns_upper, self.namespace))
  556.             self.h.write('#define %sIS_OBJECT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT))\n'%(self.ns_upper, self.ns_upper))
  557.             self.h.write('#define %sOBJECT_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), %sTYPE_OBJECT, %sObject))\n'%(self.ns_upper, self.ns_upper, self.namespace))
  558.             self.h.write('\n')
  559.             self.h.write('struct _%sObject;\n'%(self.namespace))
  560.             self.h.write('typedef struct _%sObject %sObject;\n'%(self.namespace, self.namespace))
  561.             self.h.write('typedef struct _%sObjectIface %sObjectIface;\n'%(self.namespace, self.namespace))
  562.             self.h.write('\n')
  563.             self.h.write('struct _%sObjectIface\n'%(self.namespace))
  564.             self.h.write('{\n'
  565.                          '  GTypeInterface parent_iface;\n'
  566.                          '};\n'
  567.                          '\n')
  568.             self.h.write('GType %sobject_get_type (void) G_GNUC_CONST;\n'
  569.                          '\n'
  570.                          %(self.ns_lower))
  571.             for i in self.ifaces:
  572.                 if i.deprecated:
  573.                     self.h.write('G_GNUC_DEPRECATED ')
  574.                 self.h.write ('%s *%sobject_get_%s (%sObject *object);\n'
  575.                               %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
  576.             for i in self.ifaces:
  577.                 if i.deprecated:
  578.                     self.h.write('G_GNUC_DEPRECATED ')
  579.                 self.h.write ('%s *%sobject_peek_%s (%sObject *object);\n'
  580.                               %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
  581.             self.h.write('\n')
  582.             self.h.write('#define %sTYPE_OBJECT_PROXY (%sobject_proxy_get_type ())\n'%(self.ns_upper, self.ns_lower))
  583.             self.h.write('#define %sOBJECT_PROXY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_OBJECT_PROXY, %sObjectProxy))\n'%(self.ns_upper, self.ns_upper, self.namespace))
  584.             self.h.write('#define %sOBJECT_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), %sTYPE_OBJECT_PROXY, %sObjectProxyClass))\n'%(self.ns_upper, self.ns_upper, self.namespace))
  585.             self.h.write('#define %sOBJECT_PROXY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), %sTYPE_OBJECT_PROXY, %sObjectProxyClass))\n'%(self.ns_upper, self.ns_upper, self.namespace))
  586.             self.h.write('#define %sIS_OBJECT_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT_PROXY))\n'%(self.ns_upper, self.ns_upper))
  587.             self.h.write('#define %sIS_OBJECT_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), %sTYPE_OBJECT_PROXY))\n'%(self.ns_upper, self.ns_upper))
  588.             self.h.write('\n')
  589.             self.h.write('typedef struct _%sObjectProxy %sObjectProxy;\n'%(self.namespace, self.namespace))
  590.             self.h.write('typedef struct _%sObjectProxyClass %sObjectProxyClass;\n'%(self.namespace, self.namespace))
  591.             self.h.write('typedef struct _%sObjectProxyPrivate %sObjectProxyPrivate;\n'%(self.namespace, self.namespace))
  592.             self.h.write('\n')
  593.             self.h.write('struct _%sObjectProxy\n'%(self.namespace))
  594.             self.h.write('{\n')
  595.             self.h.write('  /*< private >*/\n')
  596.             self.h.write('  GDBusObjectProxy parent_instance;\n')
  597.             self.h.write('  %sObjectProxyPrivate *priv;\n'%(self.namespace))
  598.             self.h.write('};\n')
  599.             self.h.write('\n')
  600.             self.h.write('struct _%sObjectProxyClass\n'%(self.namespace))
  601.             self.h.write('{\n')
  602.             self.h.write('  GDBusObjectProxyClass parent_class;\n')
  603.             self.h.write('};\n')
  604.             self.h.write('\n')
  605.             self.h.write('GType %sobject_proxy_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
  606.             self.h.write('%sObjectProxy *%sobject_proxy_new (GDBusConnection *connection, const gchar *object_path);\n'%(self.namespace, self.ns_lower))
  607.             self.h.write('\n')
  608.             self.h.write('#define %sTYPE_OBJECT_SKELETON (%sobject_skeleton_get_type ())\n'%(self.ns_upper, self.ns_lower))
  609.             self.h.write('#define %sOBJECT_SKELETON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_OBJECT_SKELETON, %sObjectSkeleton))\n'%(self.ns_upper, self.ns_upper, self.namespace))
  610.             self.h.write('#define %sOBJECT_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), %sTYPE_OBJECT_SKELETON, %sObjectSkeletonClass))\n'%(self.ns_upper, self.ns_upper, self.namespace))
  611.             self.h.write('#define %sOBJECT_SKELETON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), %sTYPE_OBJECT_SKELETON, %sObjectSkeletonClass))\n'%(self.ns_upper, self.ns_upper, self.namespace))
  612.             self.h.write('#define %sIS_OBJECT_SKELETON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT_SKELETON))\n'%(self.ns_upper, self.ns_upper))
  613.             self.h.write('#define %sIS_OBJECT_SKELETON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), %sTYPE_OBJECT_SKELETON))\n'%(self.ns_upper, self.ns_upper))
  614.             self.h.write('\n')
  615.             self.h.write('typedef struct _%sObjectSkeleton %sObjectSkeleton;\n'%(self.namespace, self.namespace))
  616.             self.h.write('typedef struct _%sObjectSkeletonClass %sObjectSkeletonClass;\n'%(self.namespace, self.namespace))
  617.             self.h.write('typedef struct _%sObjectSkeletonPrivate %sObjectSkeletonPrivate;\n'%(self.namespace, self.namespace))
  618.             self.h.write('\n')
  619.             self.h.write('struct _%sObjectSkeleton\n'%(self.namespace))
  620.             self.h.write('{\n')
  621.             self.h.write('  /*< private >*/\n')
  622.             self.h.write('  GDBusObjectSkeleton parent_instance;\n')
  623.             self.h.write('  %sObjectSkeletonPrivate *priv;\n'%(self.namespace))
  624.             self.h.write('};\n')
  625.             self.h.write('\n')
  626.             self.h.write('struct _%sObjectSkeletonClass\n'%(self.namespace))
  627.             self.h.write('{\n')
  628.             self.h.write('  GDBusObjectSkeletonClass parent_class;\n')
  629.             self.h.write('};\n')
  630.             self.h.write('\n')
  631.             self.h.write('GType %sobject_skeleton_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
  632.             self.h.write('%sObjectSkeleton *%sobject_skeleton_new (const gchar *object_path);\n'
  633.                          %(self.namespace, self.ns_lower))
  634.             for i in self.ifaces:
  635.                 if i.deprecated:
  636.                     self.h.write('G_GNUC_DEPRECATED ')
  637.                 self.h.write ('void %sobject_skeleton_set_%s (%sObjectSkeleton *object, %s *interface_);\n'
  638.                               %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name))
  639.             self.h.write('\n')
  640.  
  641.             self.h.write('/* ---- */\n')
  642.             self.h.write('\n')
  643.             self.h.write('#define %sTYPE_OBJECT_MANAGER_CLIENT (%sobject_manager_client_get_type ())\n'%(self.ns_upper, self.ns_lower))
  644.             self.h.write('#define %sOBJECT_MANAGER_CLIENT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), %sTYPE_OBJECT_MANAGER_CLIENT, %sObjectManagerClient))\n'%(self.ns_upper, self.ns_upper, self.namespace))
  645.             self.h.write('#define %sOBJECT_MANAGER_CLIENT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), %sTYPE_OBJECT_MANAGER_CLIENT, %sObjectManagerClientClass))\n'%(self.ns_upper, self.ns_upper, self.namespace))
  646.             self.h.write('#define %sOBJECT_MANAGER_CLIENT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), %sTYPE_OBJECT_MANAGER_CLIENT, %sObjectManagerClientClass))\n'%(self.ns_upper, self.ns_upper, self.namespace))
  647.             self.h.write('#define %sIS_OBJECT_MANAGER_CLIENT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), %sTYPE_OBJECT_MANAGER_CLIENT))\n'%(self.ns_upper, self.ns_upper))
  648.             self.h.write('#define %sIS_OBJECT_MANAGER_CLIENT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), %sTYPE_OBJECT_MANAGER_CLIENT))\n'%(self.ns_upper, self.ns_upper))
  649.             self.h.write('\n')
  650.             self.h.write('typedef struct _%sObjectManagerClient %sObjectManagerClient;\n'%(self.namespace, self.namespace))
  651.             self.h.write('typedef struct _%sObjectManagerClientClass %sObjectManagerClientClass;\n'%(self.namespace, self.namespace))
  652.             self.h.write('typedef struct _%sObjectManagerClientPrivate %sObjectManagerClientPrivate;\n'%(self.namespace, self.namespace))
  653.             self.h.write('\n')
  654.             self.h.write('struct _%sObjectManagerClient\n'%(self.namespace))
  655.             self.h.write('{\n')
  656.             self.h.write('  /*< private >*/\n')
  657.             self.h.write('  GDBusObjectManagerClient parent_instance;\n')
  658.             self.h.write('  %sObjectManagerClientPrivate *priv;\n'%(self.namespace))
  659.             self.h.write('};\n')
  660.             self.h.write('\n')
  661.             self.h.write('struct _%sObjectManagerClientClass\n'%(self.namespace))
  662.             self.h.write('{\n')
  663.             self.h.write('  GDBusObjectManagerClientClass parent_class;\n')
  664.             self.h.write('};\n')
  665.             self.h.write('\n')
  666.             self.h.write('GType %sobject_manager_client_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
  667.             self.h.write('\n')
  668.             self.h.write('GType %sobject_manager_client_get_proxy_type (GDBusObjectManagerClient *manager, const gchar *object_path, const gchar *interface_name, gpointer user_data);\n'%(self.ns_lower))
  669.             self.h.write('\n')
  670.             self.h.write('void %sobject_manager_client_new (\n'
  671.                          '    GDBusConnection        *connection,\n'
  672.                          '    GDBusObjectManagerClientFlags  flags,\n'
  673.                          '    const gchar            *name,\n'
  674.                          '    const gchar            *object_path,\n'
  675.                          '    GCancellable           *cancellable,\n'
  676.                          '    GAsyncReadyCallback     callback,\n'
  677.                          '    gpointer                user_data);\n'
  678.                          %(self.ns_lower))
  679.             self.h.write('GDBusObjectManager *%sobject_manager_client_new_finish (\n'
  680.                          '    GAsyncResult        *res,\n'
  681.                          '    GError             **error);\n'
  682.                          %(self.ns_lower))
  683.             self.h.write('GDBusObjectManager *%sobject_manager_client_new_sync (\n'
  684.                          '    GDBusConnection        *connection,\n'
  685.                          '    GDBusObjectManagerClientFlags  flags,\n'
  686.                          '    const gchar            *name,\n'
  687.                          '    const gchar            *object_path,\n'
  688.                          '    GCancellable           *cancellable,\n'
  689.                          '    GError                **error);\n'
  690.                          %(self.ns_lower))
  691.             self.h.write('\n')
  692.             self.h.write('void %sobject_manager_client_new_for_bus (\n'
  693.                          '    GBusType                bus_type,\n'
  694.                          '    GDBusObjectManagerClientFlags  flags,\n'
  695.                          '    const gchar            *name,\n'
  696.                          '    const gchar            *object_path,\n'
  697.                          '    GCancellable           *cancellable,\n'
  698.                          '    GAsyncReadyCallback     callback,\n'
  699.                          '    gpointer                user_data);\n'
  700.                          %(self.ns_lower))
  701.             self.h.write('GDBusObjectManager *%sobject_manager_client_new_for_bus_finish (\n'
  702.                          '    GAsyncResult        *res,\n'
  703.                          '    GError             **error);\n'
  704.                          %(self.ns_lower))
  705.             self.h.write('GDBusObjectManager *%sobject_manager_client_new_for_bus_sync (\n'
  706.                          '    GBusType                bus_type,\n'
  707.                          '    GDBusObjectManagerClientFlags  flags,\n'
  708.                          '    const gchar            *name,\n'
  709.                          '    const gchar            *object_path,\n'
  710.                          '    GCancellable           *cancellable,\n'
  711.                          '    GError                **error);\n'
  712.                          %(self.ns_lower))
  713.             self.h.write('\n')
  714.  
  715.     # ----------------------------------------------------------------------------------------------------
  716.  
  717.     def generate_outro(self):
  718.         self.h.write('\n'
  719.                      'G_END_DECLS\n'
  720.                      '\n'
  721.                      '#endif /* __%s__ */\n'%(self.header_guard))
  722.  
  723.     # ----------------------------------------------------------------------------------------------------
  724.  
  725.     def generate_annotations(self, prefix, annotations):
  726.         if annotations == None:
  727.             return
  728.  
  729.         n = 0
  730.         for a in annotations:
  731.             #self.generate_annotations('%s_%d'%(prefix, n), a.get_annotations())
  732.  
  733.             # skip internal annotations
  734.             if a.key.startswith('org.gtk.GDBus'):
  735.                 continue
  736.  
  737.             self.c.write('static const GDBusAnnotationInfo %s_%d =\n'
  738.                          '{\n'
  739.                          '  -1,\n'
  740.                          '  (gchar *) "%s",\n'
  741.                          '  (gchar *) "%s",\n'%(prefix, n, a.key, a.value))
  742.             if len(a.annotations) == 0:
  743.                 self.c.write('  NULL\n')
  744.             else:
  745.                 self.c.write('  (GDBusAnnotationInfo **) &%s_%d_pointers\n'%(prefix, n))
  746.             self.c.write('};\n'
  747.                          '\n')
  748.             n += 1
  749.  
  750.         if n > 0:
  751.             self.c.write('static const GDBusAnnotationInfo * const %s_pointers[] =\n'
  752.                              '{\n'%(prefix))
  753.             m = 0;
  754.             for a in annotations:
  755.                 if a.key.startswith('org.gtk.GDBus'):
  756.                     continue
  757.                 self.c.write('  &%s_%d,\n'%(prefix, m))
  758.                 m += 1
  759.             self.c.write('  NULL\n'
  760.                          '};\n'
  761.                          '\n')
  762.         return n
  763.  
  764.     def generate_args(self, prefix, args):
  765.         for a in args:
  766.             num_anno = self.generate_annotations('%s_arg_%s_annotation_info'%(prefix, a.name), a.annotations)
  767.  
  768.             self.c.write('static const _ExtendedGDBusArgInfo %s_%s =\n'
  769.                          '{\n'
  770.                          '  {\n'
  771.                          '    -1,\n'
  772.                          '    (gchar *) "%s",\n'
  773.                          '    (gchar *) "%s",\n'%(prefix, a.name, a.name, a.signature))
  774.             if num_anno == 0:
  775.                 self.c.write('    NULL\n')
  776.             else:
  777.                 self.c.write('    (GDBusAnnotationInfo **) &%s_arg_%s_annotation_info_pointers\n'%(prefix, a.name))
  778.             self.c.write('  },\n')
  779.             if not utils.lookup_annotation(a.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
  780.                 self.c.write('  FALSE\n')
  781.             else:
  782.                 self.c.write('  TRUE\n')
  783.             self.c.write('};\n'
  784.                          '\n')
  785.  
  786.         if len(args) > 0:
  787.             self.c.write('static const _ExtendedGDBusArgInfo * const %s_pointers[] =\n'
  788.                              '{\n'%(prefix))
  789.             for a in args:
  790.                 self.c.write('  &%s_%s,\n'%(prefix, a.name))
  791.             self.c.write('  NULL\n'
  792.                          '};\n'
  793.                          '\n')
  794.  
  795.     def generate_introspection_for_interface(self, i):
  796.             self.c.write('/* ---- Introspection data for %s ---- */\n'
  797.                          '\n'%(i.name))
  798.  
  799.             if len(i.methods) > 0:
  800.                 for m in i.methods:
  801.                     unix_fd = False
  802.                     if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
  803.                         unix_fd = True
  804.                     self.generate_args('_%s_method_info_%s_IN_ARG'%(i.name_lower, m.name_lower), m.in_args)
  805.                     self.generate_args('_%s_method_info_%s_OUT_ARG'%(i.name_lower, m.name_lower), m.out_args)
  806.  
  807.                     num_anno = self.generate_annotations('_%s_method_%s_annotation_info'%(i.name_lower, m.name_lower), m.annotations)
  808.  
  809.                     self.c.write('static const _ExtendedGDBusMethodInfo _%s_method_info_%s =\n'
  810.                                  '{\n'
  811.                                  '  {\n'
  812.                                  '    -1,\n'
  813.                                  '    (gchar *) "%s",\n'%(i.name_lower, m.name_lower, m.name))
  814.                     if len(m.in_args) == 0:
  815.                         self.c.write('    NULL,\n')
  816.                     else:
  817.                         self.c.write('    (GDBusArgInfo **) &_%s_method_info_%s_IN_ARG_pointers,\n'%(i.name_lower, m.name_lower))
  818.                     if len(m.out_args) == 0:
  819.                         self.c.write('    NULL,\n')
  820.                     else:
  821.                         self.c.write('    (GDBusArgInfo **) &_%s_method_info_%s_OUT_ARG_pointers,\n'%(i.name_lower, m.name_lower))
  822.                     if num_anno == 0:
  823.                         self.c.write('    NULL\n')
  824.                     else:
  825.                         self.c.write('    (GDBusAnnotationInfo **) &_%s_method_%s_annotation_info_pointers\n'%(i.name_lower, m.name_lower))
  826.                     self.c.write('  },\n'
  827.                                  '  "handle-%s",\n'
  828.                                  '  %s\n'
  829.                                  %(m.name_hyphen, 'TRUE' if unix_fd else 'FALSE'))
  830.                     self.c.write('};\n'
  831.                                  '\n')
  832.  
  833.                 self.c.write('static const _ExtendedGDBusMethodInfo * const _%s_method_info_pointers[] =\n'
  834.                              '{\n'%(i.name_lower))
  835.                 for m in i.methods:
  836.                     self.c.write('  &_%s_method_info_%s,\n'%(i.name_lower, m.name_lower))
  837.                 self.c.write('  NULL\n'
  838.                              '};\n'
  839.                              '\n')
  840.  
  841.             # ---
  842.  
  843.             if len(i.signals) > 0:
  844.                 for s in i.signals:
  845.                     self.generate_args('_%s_signal_info_%s_ARG'%(i.name_lower, s.name_lower), s.args)
  846.  
  847.                     num_anno = self.generate_annotations('_%s_signal_%s_annotation_info'%(i.name_lower, s.name_lower), s.annotations)
  848.                     self.c.write('static const _ExtendedGDBusSignalInfo _%s_signal_info_%s =\n'
  849.                                  '{\n'
  850.                                  '  {\n'
  851.                                  '    -1,\n'
  852.                                  '    (gchar *) "%s",\n'%(i.name_lower, s.name_lower, s.name))
  853.                     if len(s.args) == 0:
  854.                         self.c.write('    NULL,\n')
  855.                     else:
  856.                         self.c.write('    (GDBusArgInfo **) &_%s_signal_info_%s_ARG_pointers,\n'%(i.name_lower, s.name_lower))
  857.                     if num_anno == 0:
  858.                         self.c.write('    NULL\n')
  859.                     else:
  860.                         self.c.write('    (GDBusAnnotationInfo **) &_%s_signal_%s_annotation_info_pointers\n'%(i.name_lower, s.name_lower))
  861.                     self.c.write('  },\n'
  862.                                  '  "%s"\n'
  863.                                  %(s.name_hyphen))
  864.                     self.c.write('};\n'
  865.                                  '\n')
  866.  
  867.                 self.c.write('static const _ExtendedGDBusSignalInfo * const _%s_signal_info_pointers[] =\n'
  868.                              '{\n'%(i.name_lower))
  869.                 for s in i.signals:
  870.                     self.c.write('  &_%s_signal_info_%s,\n'%(i.name_lower, s.name_lower))
  871.                 self.c.write('  NULL\n'
  872.                              '};\n'
  873.                              '\n')
  874.  
  875.             # ---
  876.  
  877.             if len(i.properties) > 0:
  878.                 for p in i.properties:
  879.                     if p.readable and p.writable:
  880.                         access = 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE'
  881.                     elif p.readable:
  882.                         access = 'G_DBUS_PROPERTY_INFO_FLAGS_READABLE'
  883.                     elif p.writable:
  884.                         access = 'G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE'
  885.                     else:
  886.                         access = 'G_DBUS_PROPERTY_INFO_FLAGS_NONE'
  887.                     num_anno = self.generate_annotations('_%s_property_%s_annotation_info'%(i.name_lower, p.name_lower), p.annotations)
  888.                     self.c.write('static const _ExtendedGDBusPropertyInfo _%s_property_info_%s =\n'
  889.                                  '{\n'
  890.                                  '  {\n'
  891.                                  '    -1,\n'
  892.                                  '    (gchar *) "%s",\n'
  893.                                  '    (gchar *) "%s",\n'
  894.                                  '    %s,\n'%(i.name_lower, p.name_lower, p.name, p.arg.signature, access))
  895.                     if num_anno == 0:
  896.                         self.c.write('    NULL\n')
  897.                     else:
  898.                         self.c.write('    (GDBusAnnotationInfo **) &_%s_property_%s_annotation_info_pointers\n'%(i.name_lower, p.name_lower))
  899.                     self.c.write('  },\n'
  900.                                  '  "%s",\n'
  901.                                  %(p.name_hyphen))
  902.                     if not utils.lookup_annotation(p.annotations, 'org.gtk.GDBus.C.ForceGVariant'):
  903.                         self.c.write('  FALSE\n')
  904.                     else:
  905.                         self.c.write('  TRUE\n')
  906.                     self.c.write('};\n'
  907.                                  '\n')
  908.  
  909.                 self.c.write('static const _ExtendedGDBusPropertyInfo * const _%s_property_info_pointers[] =\n'
  910.                              '{\n'%(i.name_lower))
  911.                 for p in i.properties:
  912.                     self.c.write('  &_%s_property_info_%s,\n'%(i.name_lower, p.name_lower))
  913.                 self.c.write('  NULL\n'
  914.                              '};\n'
  915.                              '\n')
  916.  
  917.             num_anno = self.generate_annotations('_%s_annotation_info'%(i.name_lower), i.annotations)
  918.             self.c.write('static const _ExtendedGDBusInterfaceInfo _%s_interface_info =\n'
  919.                          '{\n'
  920.                          '  {\n'
  921.                          '    -1,\n'
  922.                          '    (gchar *) "%s",\n'%(i.name_lower, i.name))
  923.             if len(i.methods) == 0:
  924.                 self.c.write('    NULL,\n')
  925.             else:
  926.                 self.c.write('    (GDBusMethodInfo **) &_%s_method_info_pointers,\n'%(i.name_lower))
  927.             if len(i.signals) == 0:
  928.                 self.c.write('    NULL,\n')
  929.             else:
  930.                 self.c.write('    (GDBusSignalInfo **) &_%s_signal_info_pointers,\n'%(i.name_lower))
  931.             if len(i.properties) == 0:
  932.                 self.c.write('    NULL,\n')
  933.             else:
  934.                 self.c.write('    (GDBusPropertyInfo **) &_%s_property_info_pointers,\n'%(i.name_lower))
  935.             if num_anno == 0:
  936.                 self.c.write('    NULL\n')
  937.             else:
  938.                 self.c.write('    (GDBusAnnotationInfo **) &_%s_annotation_info_pointers\n'%(i.name_lower))
  939.             self.c.write('  },\n'
  940.                          '  "%s",\n'
  941.                          '};\n'
  942.                          '\n'
  943.                          %(i.name_hyphen))
  944.             self.c.write('\n')
  945.             self.c.write(self.docbook_gen.expand(
  946.                     '/**\n'
  947.                     ' * %s_interface_info:\n'
  948.                     ' *\n'
  949.                     ' * Gets a machine-readable description of the #%s D-Bus interface.\n'
  950.                     ' *\n'
  951.                     ' * Returns: (transfer none): A #GDBusInterfaceInfo. Do not free.\n'
  952.                     %(i.name_lower, i.name), False))
  953.             self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
  954.             self.c.write('GDBusInterfaceInfo *\n'
  955.                          '%s_interface_info (void)\n'
  956.                          '{\n'
  957.                          '  return (GDBusInterfaceInfo *) &_%s_interface_info.parent_struct;\n'
  958.                          '}\n'
  959.                          '\n'%(i.name_lower, i.name_lower))
  960.  
  961.             self.c.write(self.docbook_gen.expand(
  962.                     '/**\n'
  963.                     ' * %s_override_properties:\n'
  964.                     ' * @klass: The class structure for a #GObject<!-- -->-derived class.\n'
  965.                     ' * @property_id_begin: The property id to assign to the first overridden property.\n'
  966.                     ' *\n'
  967.                     ' * Overrides all #GObject properties in the #%s interface for a concrete class.\n'
  968.                     ' * The properties are overridden in the order they are defined.\n'
  969.                     ' *\n'
  970.                     ' * Returns: The last property id.\n'
  971.                     %(i.name_lower, i.camel_name), False))
  972.             self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
  973.             self.c.write('guint\n'
  974.                          '%s_override_properties (GObjectClass *klass, guint property_id_begin)\n'
  975.                          '{\n'%(i.name_lower))
  976.             for p in i.properties:
  977.                 self.c.write ('  g_object_class_override_property (klass, property_id_begin++, "%s");\n'%(p.name_hyphen))
  978.             self.c.write('  return property_id_begin - 1;\n'
  979.                          '}\n'
  980.                          '\n')
  981.             self.c.write('\n')
  982.  
  983.     # ----------------------------------------------------------------------------------------------------
  984.  
  985.     def generate_interface(self, i):
  986.         self.c.write('\n')
  987.  
  988.         self.c.write(self.docbook_gen.expand(
  989.                 '/**\n'
  990.                 ' * %s:\n'
  991.                 ' *\n'
  992.                 ' * Abstract interface type for the D-Bus interface #%s.\n'
  993.                 %(i.camel_name, i.name), False))
  994.         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
  995.         self.c.write('\n')
  996.  
  997.         self.c.write(self.docbook_gen.expand(
  998.                 '/**\n'
  999.                 ' * %sIface:\n'
  1000.                 ' * @parent_iface: The parent interface.\n'
  1001.                 %(i.camel_name), False))
  1002.  
  1003.         doc_bits = {}
  1004.         if len(i.methods) > 0:
  1005.             for m in i.methods:
  1006.                 key = (m.since, '_method_%s'%m.name_lower)
  1007.                 value  = '@handle_%s: '%(m.name_lower)
  1008.                 value += 'Handler for the #%s::handle-%s signal.'%(i.camel_name, m.name_hyphen)
  1009.                 doc_bits[key] = value
  1010.         if len(i.signals) > 0:
  1011.             for s in i.signals:
  1012.                 key = (s.since, '_signal_%s'%s.name_lower)
  1013.                 value  = '@%s: '%(s.name_lower)
  1014.                 value += 'Handler for the #%s::%s signal.'%(i.camel_name, s.name_hyphen)
  1015.                 doc_bits[key] = value
  1016.         if len(i.properties) > 0:
  1017.             for p in i.properties:
  1018.                 key = (p.since, '_prop_get_%s'%p.name_lower)
  1019.                 value  = '@get_%s: '%(p.name_lower)
  1020.                 value += 'Getter for the #%s:%s property.'%(i.camel_name, p.name_hyphen)
  1021.                 doc_bits[key] = value
  1022.         for key in sorted(doc_bits.keys(), key=utils.version_cmp_key):
  1023.             self.c.write(' * %s\n'%doc_bits[key])
  1024.  
  1025.         self.c.write(self.docbook_gen.expand(
  1026.                 ' *\n'
  1027.                 ' * Virtual table for the D-Bus interface #%s.\n'
  1028.                 %(i.name), False))
  1029.         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
  1030.         self.c.write('\n')
  1031.  
  1032.         self.c.write('typedef %sIface %sInterface;\n'%(i.camel_name, i.camel_name))
  1033.         self.c.write('G_DEFINE_INTERFACE (%s, %s, G_TYPE_OBJECT);\n'%(i.camel_name, i.name_lower))
  1034.         self.c.write('\n')
  1035.  
  1036.         self.c.write('static void\n'
  1037.                      '%s_default_init (%sIface *iface)\n'
  1038.                      '{\n'%(i.name_lower, i.camel_name));
  1039.  
  1040.         if len(i.methods) > 0:
  1041.             self.c.write('  /* GObject signals for incoming D-Bus method calls: */\n')
  1042.             for m in i.methods:
  1043.                 unix_fd = False
  1044.                 if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
  1045.                     unix_fd = True
  1046.                 self.c.write(self.docbook_gen.expand(
  1047.                         '  /**\n'
  1048.                         '   * %s::handle-%s:\n'
  1049.                         '   * @object: A #%s.\n'
  1050.                         '   * @invocation: A #GDBusMethodInvocation.\n'
  1051.                         %(i.camel_name, m.name_hyphen, i.camel_name), False))
  1052.                 if unix_fd:
  1053.                     self.c.write ('   * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
  1054.                 for a in m.in_args:
  1055.                     self.c.write ('   * @arg_%s: Argument passed by remote caller.\n'%(a.name))
  1056.                 self.c.write(self.docbook_gen.expand(
  1057.                         '   *\n'
  1058.                         '   * Signal emitted when a remote caller is invoking the %s.%s() D-Bus method.\n'
  1059.                         '   *\n'
  1060.                         '   * If a signal handler returns %%TRUE, it means the signal handler will handle the invocation (e.g. take a reference to @invocation and eventually call %s_complete_%s() or e.g. g_dbus_method_invocation_return_error() on it) and no order signal handlers will run. If no signal handler handles the invocation, the %%G_DBUS_ERROR_UNKNOWN_METHOD error is returned.\n'
  1061.                         '   *\n'
  1062.                         '   * Returns: %%TRUE if the invocation was handled, %%FALSE to let other signal handlers run.\n'
  1063.                         %(i.name, m.name, i.name_lower, m.name_lower), False))
  1064.                 self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 2)
  1065.                 if unix_fd:
  1066.                     extra_args = 2
  1067.                 else:
  1068.                     extra_args = 1
  1069.                 self.c.write('  g_signal_new ("handle-%s",\n'
  1070.                              '    G_TYPE_FROM_INTERFACE (iface),\n'
  1071.                              '    G_SIGNAL_RUN_LAST,\n'
  1072.                              '    G_STRUCT_OFFSET (%sIface, handle_%s),\n'
  1073.                              '    g_signal_accumulator_true_handled,\n'
  1074.                              '    NULL,\n' # accu_data
  1075.                              '    g_cclosure_marshal_generic,\n'
  1076.                              '    G_TYPE_BOOLEAN,\n'
  1077.                              '    %d,\n'
  1078.                              '    G_TYPE_DBUS_METHOD_INVOCATION'
  1079.                              %(m.name_hyphen, i.camel_name, m.name_lower, len(m.in_args) + extra_args))
  1080.                 if unix_fd:
  1081.                     self.c.write(', G_TYPE_UNIX_FD_LIST')
  1082.                 for a in m.in_args:
  1083.                     self.c.write (', %s'%(a.gtype))
  1084.                 self.c.write(');\n')
  1085.                 self.c.write('\n')
  1086.  
  1087.         if len(i.signals) > 0:
  1088.             self.c.write('  /* GObject signals for received D-Bus signals: */\n')
  1089.             for s in i.signals:
  1090.                 self.c.write(self.docbook_gen.expand(
  1091.                         '  /**\n'
  1092.                         '   * %s::%s:\n'
  1093.                         '   * @object: A #%s.\n'
  1094.                         %(i.camel_name, s.name_hyphen, i.camel_name), False))
  1095.                 for a in s.args:
  1096.                     self.c.write ('   * @arg_%s: Argument.\n'%(a.name))
  1097.                 self.c.write(self.docbook_gen.expand(
  1098.                         '   *\n'
  1099.                         '   * On the client-side, this signal is emitted whenever the D-Bus signal #%s::%s is received.\n'
  1100.                         '   *\n'
  1101.                         '   * On the service-side, this signal can be used with e.g. g_signal_emit_by_name() to make the object emit the D-Bus signal.\n'
  1102.                         %(i.name, s.name), False))
  1103.                 self.write_gtkdoc_deprecated_and_since_and_close(s, self.c, 2)
  1104.                 self.c.write('  g_signal_new ("%s",\n'
  1105.                              '    G_TYPE_FROM_INTERFACE (iface),\n'
  1106.                              '    G_SIGNAL_RUN_LAST,\n'
  1107.                              '    G_STRUCT_OFFSET (%sIface, %s),\n'
  1108.                              '    NULL,\n' # accumulator
  1109.                              '    NULL,\n' # accu_data
  1110.                              '    g_cclosure_marshal_generic,\n'
  1111.                              '    G_TYPE_NONE,\n'
  1112.                              '    %d'
  1113.                              %(s.name_hyphen, i.camel_name, s.name_lower, len(s.args)))
  1114.                 for a in s.args:
  1115.                     self.c.write (', %s'%(a.gtype))
  1116.                 self.c.write(');\n')
  1117.                 self.c.write('\n')
  1118.  
  1119.         if len(i.properties) > 0:
  1120.             self.c.write('  /* GObject properties for D-Bus properties: */\n')
  1121.             for p in i.properties:
  1122.                 if p.readable and p.writable:
  1123.                     hint = 'Since the D-Bus property for this #GObject property is both readable and writable, it is meaningful to both read from it and write to it on both the service- and client-side.'
  1124.                 elif p.readable:
  1125.                     hint = 'Since the D-Bus property for this #GObject property is readable but not writable, it is meaningful to read from it on both the client- and service-side. It is only meaningful, however, to write to it on the service-side.'
  1126.                 elif p.writable:
  1127.                     hint = 'Since the D-Bus property for this #GObject property is writable but not readable, it is meaningful to write to it on both the client- and service-side. It is only meaningful, however, to read from it on the service-side.'
  1128.                 else:
  1129.                     raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
  1130.                 self.c.write(self.docbook_gen.expand(
  1131.                         '  /**\n'
  1132.                         '   * %s:%s:\n'
  1133.                         '   *\n'
  1134.                         '   * Represents the D-Bus property #%s:%s.\n'
  1135.                         '   *\n'
  1136.                         '   * %s\n'
  1137.                         %(i.camel_name, p.name_hyphen, i.name, p.name, hint), False))
  1138.                 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 2)
  1139.                 self.c.write('  g_object_interface_install_property (iface,\n')
  1140.                 if p.arg.gtype == 'G_TYPE_VARIANT':
  1141.                     s = 'g_param_spec_variant ("%s", "%s", "%s", G_VARIANT_TYPE ("%s"), NULL'%(p.name_hyphen, p.name, p.name, p.arg.signature)
  1142.                 elif p.arg.signature == 'b':
  1143.                     s = 'g_param_spec_boolean ("%s", "%s", "%s", FALSE'%(p.name_hyphen, p.name, p.name)
  1144.                 elif p.arg.signature == 'y':
  1145.                     s = 'g_param_spec_uchar ("%s", "%s", "%s", 0, 255, 0'%(p.name_hyphen, p.name, p.name)
  1146.                 elif p.arg.signature == 'n':
  1147.                     s = 'g_param_spec_int ("%s", "%s", "%s", G_MININT16, G_MAXINT16, 0'%(p.name_hyphen, p.name, p.name)
  1148.                 elif p.arg.signature == 'q':
  1149.                     s = 'g_param_spec_uint ("%s", "%s", "%s", 0, G_MAXUINT16, 0'%(p.name_hyphen, p.name, p.name)
  1150.                 elif p.arg.signature == 'i':
  1151.                     s = 'g_param_spec_int ("%s", "%s", "%s", G_MININT32, G_MAXINT32, 0'%(p.name_hyphen, p.name, p.name)
  1152.                 elif p.arg.signature == 'u':
  1153.                     s = 'g_param_spec_uint ("%s", "%s", "%s", 0, G_MAXUINT32, 0'%(p.name_hyphen, p.name, p.name)
  1154.                 elif p.arg.signature == 'x':
  1155.                     s = 'g_param_spec_int64 ("%s", "%s", "%s", G_MININT64, G_MAXINT64, 0'%(p.name_hyphen, p.name, p.name)
  1156.                 elif p.arg.signature == 't':
  1157.                     s = 'g_param_spec_uint64 ("%s", "%s", "%s", 0, G_MAXUINT64, 0'%(p.name_hyphen, p.name, p.name)
  1158.                 elif p.arg.signature == 'd':
  1159.                     s = 'g_param_spec_double ("%s", "%s", "%s", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0'%(p.name_hyphen, p.name, p.name)
  1160.                 elif p.arg.signature == 's':
  1161.                     s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
  1162.                 elif p.arg.signature == 'o':
  1163.                     s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
  1164.                 elif p.arg.signature == 'g':
  1165.                     s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
  1166.                 elif p.arg.signature == 'ay':
  1167.                     s = 'g_param_spec_string ("%s", "%s", "%s", NULL'%(p.name_hyphen, p.name, p.name)
  1168.                 elif p.arg.signature == 'as':
  1169.                     s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
  1170.                 elif p.arg.signature == 'ao':
  1171.                     s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
  1172.                 elif p.arg.signature == 'aay':
  1173.                     s = 'g_param_spec_boxed ("%s", "%s", "%s", G_TYPE_STRV'%(p.name_hyphen, p.name, p.name)
  1174.                 else:
  1175.                     raise RuntimeError('Unsupported gtype %s for GParamSpec'%(p.arg.gtype))
  1176.                 self.c.write('    %s, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));'%s);
  1177.                 self.c.write('\n')
  1178.  
  1179.         self.c.write('}\n'
  1180.                      '\n')
  1181.  
  1182.     # ----------------------------------------------------------------------------------------------------
  1183.  
  1184.     def generate_property_accessors(self, i):
  1185.         for p in i.properties:
  1186.             # getter
  1187.             if p.readable and p.writable:
  1188.                 hint = 'Since this D-Bus property is both readable and writable, it is meaningful to use this function on both the client- and service-side.'
  1189.             elif p.readable:
  1190.                 hint = 'Since this D-Bus property is readable, it is meaningful to use this function on both the client- and service-side.'
  1191.             elif p.writable:
  1192.                 hint = 'Since this D-Bus property is not readable, it is only meaningful to use this function on the service-side.'
  1193.             else:
  1194.                 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
  1195.             self.c.write(self.docbook_gen.expand(
  1196.                     '/**\n'
  1197.                     ' * %s_get_%s: (skip)\n'
  1198.                     ' * @object: A #%s.\n'
  1199.                     ' *\n'
  1200.                     ' * Gets the value of the #%s:%s D-Bus property.\n'
  1201.                     ' *\n'
  1202.                     ' * %s\n'
  1203.                     ' *\n'
  1204.                     %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint), False))
  1205.             if p.arg.free_func != None:
  1206.                 self.c.write(' * <warning>The returned value is only valid until the property changes so on the client-side it is only safe to use this function on the thread where @object was constructed. Use %s_dup_%s() if on another thread.</warning>\n'
  1207.                              ' *\n'
  1208.                              ' * Returns: (transfer none): The property value or %%NULL if the property is not set. Do not free the returned value, it belongs to @object.\n'
  1209.                              %(i.name_lower, p.name_lower))
  1210.             else:
  1211.                 self.c.write(' * Returns: The property value.\n')
  1212.             self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
  1213.             self.c.write('%s\n'
  1214.                          '%s_get_%s (%s *object)\n'
  1215.                          '{\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
  1216.             self.c.write('  return %s%s_GET_IFACE (object)->get_%s (object);\n'%(i.ns_upper, i.name_upper, p.name_lower))
  1217.             self.c.write('}\n')
  1218.             self.c.write('\n')
  1219.             if p.arg.free_func != None:
  1220.  
  1221.                 self.c.write(self.docbook_gen.expand(
  1222.                         '/**\n'
  1223.                         ' * %s_dup_%s: (skip)\n'
  1224.                         ' * @object: A #%s.\n'
  1225.                         ' *\n'
  1226.                         ' * Gets a copy of the #%s:%s D-Bus property.\n'
  1227.                         ' *\n'
  1228.                         ' * %s\n'
  1229.                         ' *\n'
  1230.                         ' * Returns: (transfer full): The property value or %%NULL if the property is not set. The returned value should be freed with %s().\n'
  1231.                         %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint, p.arg.free_func), False))
  1232.                 self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
  1233.                 self.c.write('%s\n'
  1234.                              '%s_dup_%s (%s *object)\n'
  1235.                              '{\n'
  1236.                              '  %svalue;\n'%(p.arg.ctype_in_dup, i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in_dup))
  1237.                 self.c.write('  g_object_get (G_OBJECT (object), "%s", &value, NULL);\n'%(p.name_hyphen))
  1238.                 self.c.write('  return value;\n')
  1239.                 self.c.write('}\n')
  1240.                 self.c.write('\n')
  1241.  
  1242.             # setter
  1243.             if p.readable and p.writable:
  1244.                 hint = 'Since this D-Bus property is both readable and writable, it is meaningful to use this function on both the client- and service-side.'
  1245.             elif p.readable:
  1246.                 hint = 'Since this D-Bus property is not writable, it is only meaningful to use this function on the service-side.'
  1247.             elif p.writable:
  1248.                 hint = 'Since this D-Bus property is writable, it is meaningful to use this function on both the client- and service-side.'
  1249.             else:
  1250.                 raise RuntimeError('Cannot handle property %s that neither readable nor writable'%(p.name))
  1251.             self.c.write(self.docbook_gen.expand(
  1252.                     '/**\n'
  1253.                     ' * %s_set_%s: (skip)\n'
  1254.                     ' * @object: A #%s.\n'
  1255.                     ' * @value: The value to set.\n'
  1256.                     ' *\n'
  1257.                     ' * Sets the #%s:%s D-Bus property to @value.\n'
  1258.                     ' *\n'
  1259.                     ' * %s\n'
  1260.                     %(i.name_lower, p.name_lower, i.camel_name, i.name, p.name, hint), False))
  1261.             self.write_gtkdoc_deprecated_and_since_and_close(p, self.c, 0)
  1262.             self.c.write('void\n'
  1263.                          '%s_set_%s (%s *object, %svalue)\n'
  1264.                          '{\n'%(i.name_lower, p.name_lower, i.camel_name, p.arg.ctype_in, ))
  1265.             self.c.write('  g_object_set (G_OBJECT (object), "%s", value, NULL);\n'%(p.name_hyphen))
  1266.             self.c.write('}\n')
  1267.             self.c.write('\n')
  1268.  
  1269.     # ---------------------------------------------------------------------------------------------------
  1270.  
  1271.     def generate_signal_emitters(self, i):
  1272.         for s in i.signals:
  1273.             self.c.write(self.docbook_gen.expand(
  1274.                     '/**\n'
  1275.                     ' * %s_emit_%s:\n'
  1276.                     ' * @object: A #%s.\n'
  1277.                     %(i.name_lower, s.name_lower, i.camel_name), False))
  1278.             for a in s.args:
  1279.                 self.c.write(' * @arg_%s: Argument to pass with the signal.\n'%(a.name))
  1280.             self.c.write(self.docbook_gen.expand(
  1281.                     ' *\n'
  1282.                     ' * Emits the #%s::%s D-Bus signal.\n'
  1283.                     %(i.name, s.name), False))
  1284.             self.write_gtkdoc_deprecated_and_since_and_close(s, self.c, 0)
  1285.             self.c.write('void\n'
  1286.                          '%s_emit_%s (\n'
  1287.                          '    %s *object'%(i.name_lower, s.name_lower, i.camel_name))
  1288.             for a in s.args:
  1289.                 self.c.write(',\n    %sarg_%s'%(a.ctype_in, a.name))
  1290.             self.c.write(')\n'
  1291.                          '{\n'
  1292.                          '  g_signal_emit_by_name (object, "%s"'%(s.name_hyphen))
  1293.             for a in s.args:
  1294.                 self.c.write(', arg_%s'%a.name)
  1295.             self.c.write(');\n')
  1296.             self.c.write('}\n'
  1297.                          '\n')
  1298.  
  1299.     # ---------------------------------------------------------------------------------------------------
  1300.  
  1301.     def generate_method_calls(self, i):
  1302.         for m in i.methods:
  1303.             unix_fd = False
  1304.             if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
  1305.                 unix_fd = True
  1306.             # async begin
  1307.             self.c.write('/**\n'
  1308.                          ' * %s_call_%s:\n'
  1309.                          ' * @proxy: A #%sProxy.\n'
  1310.                          %(i.name_lower, m.name_lower, i.camel_name))
  1311.             for a in m.in_args:
  1312.                 self.c.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name))
  1313.             if unix_fd:
  1314.                 self.c.write(' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
  1315.             self.c.write(self.docbook_gen.expand(
  1316.                     ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
  1317.                     ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %%NULL.\n'
  1318.                     ' * @user_data: User data to pass to @callback.\n'
  1319.                     ' *\n'
  1320.                     ' * Asynchronously invokes the %s.%s() D-Bus method on @proxy.\n'
  1321.                     ' * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.\n'
  1322.                     ' * You can then call %s_call_%s_finish() to get the result of the operation.\n'
  1323.                     ' *\n'
  1324.                     ' * See %s_call_%s_sync() for the synchronous, blocking version of this method.\n'
  1325.                     %(i.name, m.name, i.name_lower, m.name_lower, i.name_lower, m.name_lower), False))
  1326.             self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
  1327.             self.c.write('void\n'
  1328.                          '%s_call_%s (\n'
  1329.                          '    %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
  1330.             for a in m.in_args:
  1331.                 self.c.write(',\n    %sarg_%s'%(a.ctype_in, a.name))
  1332.             if unix_fd:
  1333.                 self.c.write(',\n    GUnixFDList *fd_list')
  1334.             self.c.write(',\n'
  1335.                          '    GCancellable *cancellable,\n'
  1336.                          '    GAsyncReadyCallback callback,\n'
  1337.                          '    gpointer user_data)\n'
  1338.                          '{\n')
  1339.             if unix_fd:
  1340.                 self.c.write('  g_dbus_proxy_call_with_unix_fd_list (G_DBUS_PROXY (proxy),\n')
  1341.             else:
  1342.                 self.c.write('  g_dbus_proxy_call (G_DBUS_PROXY (proxy),\n')
  1343.             self.c.write('    "%s",\n'
  1344.                          '    g_variant_new ("('%(m.name))
  1345.             for a in m.in_args:
  1346.                 self.c.write('%s'%(a.format_in))
  1347.             self.c.write(')"')
  1348.             for a in m.in_args:
  1349.                 self.c.write(',\n                   arg_%s'%(a.name))
  1350.             self.c.write('),\n'
  1351.                          '    G_DBUS_CALL_FLAGS_NONE,\n'
  1352.                          '    -1,\n')
  1353.             if unix_fd:
  1354.                 self.c.write('    fd_list,\n')
  1355.             self.c.write('    cancellable,\n'
  1356.                          '    callback,\n'
  1357.                          '    user_data);\n')
  1358.             self.c.write('}\n'
  1359.                          '\n')
  1360.             # async finish
  1361.             self.c.write('/**\n'
  1362.                          ' * %s_call_%s_finish:\n'
  1363.                          ' * @proxy: A #%sProxy.\n'
  1364.                          %(i.name_lower, m.name_lower, i.camel_name))
  1365.             for a in m.out_args:
  1366.                 self.c.write(' * @out_%s: (out): Return location for return parameter or %%NULL to ignore.\n'%(a.name))
  1367.             if unix_fd:
  1368.                 self.c.write(' * @out_fd_list: (out): Return location for a #GUnixFDList or %NULL.\n')
  1369.             self.c.write(self.docbook_gen.expand(
  1370.                     ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_call_%s().\n'
  1371.                     ' * @error: Return location for error or %%NULL.\n'
  1372.                     ' *\n'
  1373.                     ' * Finishes an operation started with %s_call_%s().\n'
  1374.                     ' *\n'
  1375.                     ' * Returns: (skip): %%TRUE if the call succeded, %%FALSE if @error is set.\n'
  1376.                     %(i.name_lower, m.name_lower, i.name_lower, m.name_lower), False))
  1377.             self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
  1378.             self.c.write('gboolean\n'
  1379.                          '%s_call_%s_finish (\n'
  1380.                          '    %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
  1381.             for a in m.out_args:
  1382.                 self.c.write(',\n    %sout_%s'%(a.ctype_out, a.name))
  1383.             if unix_fd:
  1384.                 self.c.write(',\n    GUnixFDList **out_fd_list')
  1385.             self.c.write(',\n'
  1386.                          '    GAsyncResult *res,\n'
  1387.                          '    GError **error)\n'
  1388.                          '{\n'
  1389.                          '  GVariant *_ret;\n')
  1390.             if unix_fd:
  1391.                 self.c.write('  _ret = g_dbus_proxy_call_with_unix_fd_list_finish (G_DBUS_PROXY (proxy), out_fd_list, res, error);\n')
  1392.             else:
  1393.                 self.c.write('  _ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), res, error);\n')
  1394.             self.c.write('  if (_ret == NULL)\n'
  1395.                          '    goto _out;\n')
  1396.             self.c.write('  g_variant_get (_ret,\n'
  1397.                          '                 \"(')
  1398.             for a in m.out_args:
  1399.                 self.c.write('%s'%(a.format_out))
  1400.             self.c.write(')"')
  1401.             for a in m.out_args:
  1402.                 self.c.write(',\n                 out_%s'%(a.name))
  1403.             self.c.write(');\n'
  1404.                          '  g_variant_unref (_ret);\n')
  1405.             self.c.write('_out:\n'
  1406.                          '  return _ret != NULL;\n'
  1407.                          '}\n'
  1408.                          '\n')
  1409.  
  1410.  
  1411.             # sync
  1412.             self.c.write('/**\n'
  1413.                          ' * %s_call_%s_sync:\n'
  1414.                          ' * @proxy: A #%sProxy.\n'
  1415.                          %(i.name_lower, m.name_lower, i.camel_name))
  1416.             for a in m.in_args:
  1417.                 self.c.write(' * @arg_%s: Argument to pass with the method invocation.\n'%(a.name))
  1418.             if unix_fd:
  1419.                 self.c.write(' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
  1420.             for a in m.out_args:
  1421.                 self.c.write(' * @out_%s: (out): Return location for return parameter or %%NULL to ignore.\n'%(a.name))
  1422.             if unix_fd:
  1423.                 self.c.write(' * @out_fd_list: (out): Return location for a #GUnixFDList or %NULL.\n')
  1424.             self.c.write(self.docbook_gen.expand(
  1425.                     ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
  1426.                     ' * @error: Return location for error or %%NULL.\n'
  1427.                     ' *\n'
  1428.                     ' * Synchronously invokes the %s.%s() D-Bus method on @proxy. The calling thread is blocked until a reply is received.\n'
  1429.                     ' *\n'
  1430.                     ' * See %s_call_%s() for the asynchronous version of this method.\n'
  1431.                     ' *\n'
  1432.                     ' * Returns: (skip): %%TRUE if the call succeded, %%FALSE if @error is set.\n'
  1433.                     %(i.name, m.name, i.name_lower, m.name_lower), False))
  1434.             self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
  1435.             self.c.write('gboolean\n'
  1436.                          '%s_call_%s_sync (\n'
  1437.                          '    %s *proxy'%(i.name_lower, m.name_lower, i.camel_name))
  1438.             for a in m.in_args:
  1439.                 self.c.write(',\n    %sarg_%s'%(a.ctype_in, a.name))
  1440.             if unix_fd:
  1441.                 self.c.write(',\n    GUnixFDList  *fd_list')
  1442.             for a in m.out_args:
  1443.                 self.c.write(',\n    %sout_%s'%(a.ctype_out, a.name))
  1444.             if unix_fd:
  1445.                 self.c.write(',\n    GUnixFDList **out_fd_list')
  1446.             self.c.write(',\n'
  1447.                          '    GCancellable *cancellable,\n'
  1448.                          '    GError **error)\n'
  1449.                          '{\n'
  1450.                          '  GVariant *_ret;\n')
  1451.             if unix_fd:
  1452.                 self.c.write('  _ret = g_dbus_proxy_call_with_unix_fd_list_sync (G_DBUS_PROXY (proxy),\n')
  1453.             else:
  1454.                 self.c.write('  _ret = g_dbus_proxy_call_sync (G_DBUS_PROXY (proxy),\n')
  1455.             self.c.write('    "%s",\n'
  1456.                          '    g_variant_new ("('%(m.name))
  1457.             for a in m.in_args:
  1458.                 self.c.write('%s'%(a.format_in))
  1459.             self.c.write(')"')
  1460.             for a in m.in_args:
  1461.                 self.c.write(',\n                   arg_%s'%(a.name))
  1462.             self.c.write('),\n'
  1463.                          '    G_DBUS_CALL_FLAGS_NONE,\n'
  1464.                          '    -1,\n')
  1465.             if unix_fd:
  1466.                 self.c.write('    fd_list,\n'
  1467.                              '    out_fd_list,\n')
  1468.             self.c.write('    cancellable,\n'
  1469.                          '    error);\n'
  1470.                          '  if (_ret == NULL)\n'
  1471.                          '    goto _out;\n')
  1472.             self.c.write('  g_variant_get (_ret,\n'
  1473.                          '                 \"(')
  1474.             for a in m.out_args:
  1475.                 self.c.write('%s'%(a.format_out))
  1476.             self.c.write(')"')
  1477.             for a in m.out_args:
  1478.                 self.c.write(',\n                 out_%s'%(a.name))
  1479.             self.c.write(');\n'
  1480.                          '  g_variant_unref (_ret);\n')
  1481.             self.c.write('_out:\n'
  1482.                          '  return _ret != NULL;\n'
  1483.                          '}\n'
  1484.                          '\n')
  1485.  
  1486.     # ---------------------------------------------------------------------------------------------------
  1487.  
  1488.     def generate_method_completers(self, i):
  1489.         for m in i.methods:
  1490.             unix_fd = False
  1491.             if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
  1492.                 unix_fd = True
  1493.             self.c.write('/**\n'
  1494.                          ' * %s_complete_%s:\n'
  1495.                          ' * @object: A #%s.\n'
  1496.                          ' * @invocation: (transfer full): A #GDBusMethodInvocation.\n'
  1497.                          %(i.name_lower, m.name_lower, i.camel_name))
  1498.             if unix_fd:
  1499.                 self.c.write (' * @fd_list: (allow-none): A #GUnixFDList or %NULL.\n')
  1500.             for a in m.out_args:
  1501.                 self.c.write(' * @%s: Parameter to return.\n'%(a.name))
  1502.             self.c.write(self.docbook_gen.expand(
  1503.                     ' *\n'
  1504.                     ' * Helper function used in service implementations to finish handling invocations of the %s.%s() D-Bus method. If you instead want to finish handling an invocation by returning an error, use g_dbus_method_invocation_return_error() or similar.\n'
  1505.                     ' *\n'
  1506.                     ' * This method will free @invocation, you cannot use it afterwards.\n'
  1507.                     %(i.name, m.name), False))
  1508.             self.write_gtkdoc_deprecated_and_since_and_close(m, self.c, 0)
  1509.             self.c.write('void\n'
  1510.                          '%s_complete_%s (\n'
  1511.                          '    %s *object,\n'
  1512.                          '    GDBusMethodInvocation *invocation'%(i.name_lower, m.name_lower, i.camel_name))
  1513.             if unix_fd:
  1514.                 self.c.write(',\n    GUnixFDList *fd_list')
  1515.             for a in m.out_args:
  1516.                 self.c.write(',\n    %s%s'%(a.ctype_in, a.name))
  1517.             self.c.write(')\n'
  1518.                          '{\n')
  1519.  
  1520.             if unix_fd:
  1521.                 self.c.write('  g_dbus_method_invocation_return_value_with_unix_fd_list (invocation,\n'
  1522.                              '    g_variant_new ("(')
  1523.             else:
  1524.                 self.c.write('  g_dbus_method_invocation_return_value (invocation,\n'
  1525.                              '    g_variant_new ("(')
  1526.             for a in m.out_args:
  1527.                 self.c.write('%s'%(a.format_in))
  1528.             self.c.write(')"')
  1529.             for a in m.out_args:
  1530.                 self.c.write(',\n                   %s'%(a.name))
  1531.             if unix_fd:
  1532.                 self.c.write('),\n    fd_list);\n')
  1533.             else:
  1534.                 self.c.write('));\n')
  1535.             self.c.write('}\n'
  1536.                          '\n')
  1537.  
  1538.     # ---------------------------------------------------------------------------------------------------
  1539.  
  1540.     def generate_proxy(self, i):
  1541.         # class boilerplate
  1542.         self.c.write('/* ------------------------------------------------------------------------ */\n'
  1543.                      '\n')
  1544.  
  1545.         self.c.write(self.docbook_gen.expand(
  1546.                 '/**\n'
  1547.                 ' * %sProxy:\n'
  1548.                 ' *\n'
  1549.                 ' * The #%sProxy structure contains only private data and should only be accessed using the provided API.\n'
  1550.                 %(i.camel_name, i.camel_name), False))
  1551.         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
  1552.         self.c.write('\n')
  1553.  
  1554.         self.c.write(self.docbook_gen.expand(
  1555.                 '/**\n'
  1556.                 ' * %sProxyClass:\n'
  1557.                 ' * @parent_class: The parent class.\n'
  1558.                 ' *\n'
  1559.                 ' * Class structure for #%sProxy.\n'
  1560.                 %(i.camel_name, i.camel_name), False))
  1561.         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
  1562.         self.c.write('\n')
  1563.  
  1564.         self.c.write('struct _%sProxyPrivate\n'
  1565.                      '{\n'
  1566.                      '  GData *qdata;\n'
  1567.                      '};\n'
  1568.                      '\n'%i.camel_name)
  1569.  
  1570.         self.c.write('static void %s_proxy_iface_init (%sIface *iface);\n'
  1571.                      '\n'%(i.name_lower, i.camel_name))
  1572.         self.c.write('G_DEFINE_TYPE_WITH_CODE (%sProxy, %s_proxy, G_TYPE_DBUS_PROXY,\n'%(i.camel_name, i.name_lower))
  1573.         self.c.write('                         G_ADD_PRIVATE (%sProxy)\n'%(i.camel_name))
  1574.         self.c.write('                         G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_proxy_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
  1575.  
  1576.         # finalize
  1577.         self.c.write('static void\n'
  1578.                      '%s_proxy_finalize (GObject *object)\n'
  1579.                      '{\n'%(i.name_lower))
  1580.         self.c.write('  %sProxy *proxy = %s%s_PROXY (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
  1581.         self.c.write('  g_datalist_clear (&proxy->priv->qdata);\n')
  1582.         self.c.write('  G_OBJECT_CLASS (%s_proxy_parent_class)->finalize (object);\n'
  1583.                      '}\n'
  1584.                      '\n'%(i.name_lower))
  1585.  
  1586.         # property accessors
  1587.         #
  1588.         # Note that we are guaranteed that prop_id starts at 1 and is
  1589.         # laid out in the same order as introspection data pointers
  1590.         #
  1591.         self.c.write('static void\n'
  1592.                      '%s_proxy_get_property (GObject      *object,\n'
  1593.                      '  guint         prop_id,\n'
  1594.                      '  GValue       *value,\n'
  1595.                      '  GParamSpec   *pspec G_GNUC_UNUSED)\n'
  1596.                      '{\n'%(i.name_lower))
  1597.         if len(i.properties) > 0:
  1598.             self.c.write('  const _ExtendedGDBusPropertyInfo *info;\n'
  1599.                          '  GVariant *variant;\n'
  1600.                          '  g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
  1601.                          '  info = _%s_property_info_pointers[prop_id - 1];\n'
  1602.                          '  variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (object), info->parent_struct.name);\n'
  1603.                          '  if (info->use_gvariant)\n'
  1604.                          '    {\n'
  1605.                          '      g_value_set_variant (value, variant);\n'
  1606.                          '    }\n'
  1607.                          '  else\n'
  1608.                          '    {\n'
  1609.                          # could be that we don't have the value in cache - in that case, we do
  1610.                          # nothing and the user gets the default value for the GType
  1611.                          '      if (variant != NULL)\n'
  1612.                          '        g_dbus_gvariant_to_gvalue (variant, value);\n'
  1613.                          '    }\n'
  1614.                          '  if (variant != NULL)\n'
  1615.                          '    g_variant_unref (variant);\n'
  1616.                          %(len(i.properties), i.name_lower))
  1617.         self.c.write('}\n'
  1618.                      '\n')
  1619.         if len(i.properties) > 0:
  1620.             self.c.write('static void\n'
  1621.                          '%s_proxy_set_property_cb (GDBusProxy *proxy,\n'
  1622.                          '  GAsyncResult *res,\n'
  1623.                          '  gpointer      user_data)\n'
  1624.                          '{\n'%(i.name_lower))
  1625.             self.c.write('  const _ExtendedGDBusPropertyInfo *info = user_data;\n'
  1626.                          '  GError *error;\n'
  1627.                          '  error = NULL;\n'
  1628.                          '  if (!g_dbus_proxy_call_finish (proxy, res, &error))\n'
  1629.                          '    {\n'
  1630.                          '      g_warning ("Error setting property \'%%s\' on interface %s: %%s (%%s, %%d)",\n'
  1631.                          '                 info->parent_struct.name, \n'
  1632.                          '                 error->message, g_quark_to_string (error->domain), error->code);\n'
  1633.                          '      g_error_free (error);\n'
  1634.                          '    }\n'
  1635.                          %(i.name))
  1636.             self.c.write('}\n'
  1637.                          '\n')
  1638.         self.c.write('static void\n'
  1639.                      '%s_proxy_set_property (GObject      *object,\n'
  1640.                      '  guint         prop_id,\n'
  1641.                      '  const GValue *value,\n'
  1642.                      '  GParamSpec   *pspec G_GNUC_UNUSED)\n'
  1643.                      '{\n'%(i.name_lower))
  1644.         if len(i.properties) > 0:
  1645.             self.c.write('  const _ExtendedGDBusPropertyInfo *info;\n'
  1646.                          '  GVariant *variant;\n'
  1647.                          '  g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
  1648.                          '  info = _%s_property_info_pointers[prop_id - 1];\n'
  1649.                          '  variant = g_dbus_gvalue_to_gvariant (value, G_VARIANT_TYPE (info->parent_struct.signature));\n'
  1650.                          '  g_dbus_proxy_call (G_DBUS_PROXY (object),\n'
  1651.                          '    "org.freedesktop.DBus.Properties.Set",\n'
  1652.                          '    g_variant_new ("(ssv)", "%s", info->parent_struct.name, variant),\n'
  1653.                          '    G_DBUS_CALL_FLAGS_NONE,\n'
  1654.                          '    -1,\n'
  1655.                          '    NULL, (GAsyncReadyCallback) %s_proxy_set_property_cb, (GDBusPropertyInfo *) &info->parent_struct);\n'
  1656.                          '  g_variant_unref (variant);\n'
  1657.                          %(len(i.properties), i.name_lower, i.name, i.name_lower))
  1658.         self.c.write('}\n'
  1659.                      '\n')
  1660.  
  1661.         # signal received
  1662.         self.c.write('static void\n'
  1663.                      '%s_proxy_g_signal (GDBusProxy *proxy,\n'
  1664.                      '  const gchar *sender_name G_GNUC_UNUSED,\n'
  1665.                      '  const gchar *signal_name,\n'
  1666.                      '  GVariant *parameters)\n'
  1667.                      '{\n'%(i.name_lower))
  1668.         self.c.write('  _ExtendedGDBusSignalInfo *info;\n'
  1669.                      '  GVariantIter iter;\n'
  1670.                      '  GVariant *child;\n'
  1671.                      '  GValue *paramv;\n'
  1672.                      '  guint num_params;\n'
  1673.                      '  guint n;\n'
  1674.                      '  guint signal_id;\n');
  1675.         # Note: info could be NULL if we are talking to a newer version of the interface
  1676.         self.c.write('  info = (_ExtendedGDBusSignalInfo *) g_dbus_interface_info_lookup_signal ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, signal_name);\n'
  1677.                      '  if (info == NULL)\n'
  1678.                      '    return;\n'
  1679.                      %(i.name_lower))
  1680.         self.c.write ('  num_params = g_variant_n_children (parameters);\n'
  1681.                       '  paramv = g_new0 (GValue, num_params + 1);\n'
  1682.                       '  g_value_init (¶mv[0], %sTYPE_%s);\n'
  1683.                       '  g_value_set_object (¶mv[0], proxy);\n'
  1684.                       %(i.ns_upper, i.name_upper))
  1685.         self.c.write('  g_variant_iter_init (&iter, parameters);\n'
  1686.                      '  n = 1;\n'
  1687.                      '  while ((child = g_variant_iter_next_value (&iter)) != NULL)\n'
  1688.                      '    {\n'
  1689.                      '      _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.args[n - 1];\n'
  1690.                      '      if (arg_info->use_gvariant)\n'
  1691.                      '        {\n'
  1692.                      '          g_value_init (¶mv[n], G_TYPE_VARIANT);\n'
  1693.                      '          g_value_set_variant (¶mv[n], child);\n'
  1694.                      '          n++;\n'
  1695.                      '        }\n'
  1696.                      '      else\n'
  1697.                      '        g_dbus_gvariant_to_gvalue (child, ¶mv[n++]);\n'
  1698.                      '      g_variant_unref (child);\n'
  1699.                      '    }\n'
  1700.                      )
  1701.         self.c.write('  signal_id = g_signal_lookup (info->signal_name, %sTYPE_%s);\n'
  1702.                      %(i.ns_upper, i.name_upper))
  1703.         self.c.write('  g_signal_emitv (paramv, signal_id, 0, NULL);\n')
  1704.         self.c.write('  for (n = 0; n < num_params + 1; n++)\n'
  1705.                      '    g_value_unset (¶mv[n]);\n'
  1706.                      '  g_free (paramv);\n')
  1707.         self.c.write('}\n'
  1708.                      '\n')
  1709.  
  1710.         # property changed
  1711.         self.c.write('static void\n'
  1712.                      '%s_proxy_g_properties_changed (GDBusProxy *_proxy,\n'
  1713.                      '  GVariant *changed_properties,\n'
  1714.                      '  const gchar *const *invalidated_properties)\n'
  1715.                      '{\n'%(i.name_lower))
  1716.         # Note: info could be NULL if we are talking to a newer version of the interface
  1717.         self.c.write('  %sProxy *proxy = %s%s_PROXY (_proxy);\n'
  1718.                      '  guint n;\n'
  1719.                      '  const gchar *key;\n'
  1720.                      '  GVariantIter *iter;\n'
  1721.                      '  _ExtendedGDBusPropertyInfo *info;\n'
  1722.                      '  g_variant_get (changed_properties, "a{sv}", &iter);\n'
  1723.                      '  while (g_variant_iter_next (iter, "{&sv}", &key, NULL))\n'
  1724.                      '    {\n'
  1725.                      '      info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, key);\n'
  1726.                      '      g_datalist_remove_data (&proxy->priv->qdata, key);\n'
  1727.                      '      if (info != NULL)\n'
  1728.                      '        g_object_notify (G_OBJECT (proxy), info->hyphen_name);\n'
  1729.                      '    }\n'
  1730.                      '  g_variant_iter_free (iter);\n'
  1731.                      '  for (n = 0; invalidated_properties[n] != NULL; n++)\n'
  1732.                      '    {\n'
  1733.                      '      info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, invalidated_properties[n]);\n'
  1734.                      '      g_datalist_remove_data (&proxy->priv->qdata, invalidated_properties[n]);\n'
  1735.                      '      if (info != NULL)\n'
  1736.                      '        g_object_notify (G_OBJECT (proxy), info->hyphen_name);\n'
  1737.                      '    }\n'
  1738.                      '}\n'
  1739.                      '\n'
  1740.                      %(i.camel_name, i.ns_upper, i.name_upper,
  1741.                        i.name_lower, i.name_lower))
  1742.  
  1743.         # property vfuncs
  1744.         for p in i.properties:
  1745.             nul_value = '0'
  1746.             if p.arg.free_func != None:
  1747.                 nul_value = 'NULL'
  1748.             self.c.write('static %s\n'
  1749.                          '%s_proxy_get_%s (%s *object)\n'
  1750.                          '{\n'
  1751.                          '  %sProxy *proxy = %s%s_PROXY (object);\n'
  1752.                          '  GVariant *variant;\n'
  1753.                          '  %svalue = %s;\n'%(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name,
  1754.                                               i.camel_name, i.ns_upper, i.name_upper,
  1755.                                               p.arg.ctype_in, nul_value))
  1756.             # For some property types, we have to free the returned
  1757.             # value (or part of it, e.g. the container) because of how
  1758.             # GVariant works.. see https://bugzilla.gnome.org/show_bug.cgi?id=657100
  1759.             # for details
  1760.             #
  1761.             free_container = False;
  1762.             if p.arg.gvariant_get == 'g_variant_get_strv' or p.arg.gvariant_get == 'g_variant_get_objpathv' or p.arg.gvariant_get == 'g_variant_get_bytestring_array':
  1763.                 free_container = True;
  1764.             # If already using an old value for strv, objpathv, bytestring_array (see below),
  1765.             # then just return that... that way the result from multiple consecutive calls
  1766.             # to the getter are valid as long as they're freed
  1767.             #
  1768.             if free_container:
  1769.                 self.c.write('  value = g_datalist_get_data (&proxy->priv->qdata, \"%s\");\n'
  1770.                              '  if (value != NULL)\n'
  1771.                              '    return value;\n'
  1772.                              %(p.name))
  1773.             self.c.write('  variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), \"%s\");\n'%(p.name))
  1774.             if p.arg.gtype == 'G_TYPE_VARIANT':
  1775.                 self.c.write('  value = variant;\n')
  1776.                 self.c.write('  if (variant != NULL)\n')
  1777.                 self.c.write('    g_variant_unref (variant);\n')
  1778.             else:
  1779.                 self.c.write('  if (variant != NULL)\n'
  1780.                              '    {\n')
  1781.                 extra_len = ''
  1782.                 if p.arg.gvariant_get == 'g_variant_get_string' or p.arg.gvariant_get == 'g_variant_get_strv' or p.arg.gvariant_get == 'g_variant_get_objv' or p.arg.gvariant_get == 'g_variant_get_bytestring_array':
  1783.                     extra_len = ', NULL'
  1784.                 self.c.write('      value = %s (variant%s);\n'%(p.arg.gvariant_get, extra_len))
  1785.                 if free_container:
  1786.                     self.c.write('      g_datalist_set_data_full (&proxy->priv->qdata, \"%s\", (gpointer) value, g_free);\n'
  1787.                                  %(p.name))
  1788.                 self.c.write('      g_variant_unref (variant);\n')
  1789.                 self.c.write('    }\n')
  1790.             self.c.write('  return value;\n')
  1791.             self.c.write('}\n')
  1792.             self.c.write('\n')
  1793.  
  1794.         # class boilerplate
  1795.         self.c.write('static void\n'
  1796.                      '%s_proxy_init (%sProxy *proxy)\n'
  1797.                      '{\n'
  1798.                      '  proxy->priv = %s_proxy_get_instance_private (proxy);\n'
  1799.                      '  g_dbus_proxy_set_interface_info (G_DBUS_PROXY (proxy), %s_interface_info ());\n'
  1800.                      '}\n'
  1801.                      '\n'
  1802.                      %(i.name_lower, i.camel_name,
  1803.                        i.name_lower,
  1804.                        i.name_lower))
  1805.         self.c.write('static void\n'
  1806.                      '%s_proxy_class_init (%sProxyClass *klass)\n'
  1807.                      '{\n'
  1808.                      '  GObjectClass *gobject_class;\n'
  1809.                      '  GDBusProxyClass *proxy_class;\n'
  1810.                      '\n'
  1811.                      '  gobject_class = G_OBJECT_CLASS (klass);\n'
  1812.                      '  gobject_class->finalize     = %s_proxy_finalize;\n'
  1813.                      '  gobject_class->get_property = %s_proxy_get_property;\n'
  1814.                      '  gobject_class->set_property = %s_proxy_set_property;\n'
  1815.                      '\n'
  1816.                      '  proxy_class = G_DBUS_PROXY_CLASS (klass);\n'
  1817.                      '  proxy_class->g_signal = %s_proxy_g_signal;\n'
  1818.                      '  proxy_class->g_properties_changed = %s_proxy_g_properties_changed;\n'
  1819.                      '\n'%(i.name_lower, i.camel_name,
  1820.                            i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name_lower))
  1821.         if len(i.properties) > 0:
  1822.             self.c.write('\n'
  1823.                          '  %s_override_properties (gobject_class, 1);\n'%(i.name_lower))
  1824.         self.c.write('}\n'
  1825.                      '\n')
  1826.  
  1827.         self.c.write('static void\n'
  1828.                      '%s_proxy_iface_init (%sIface *iface)\n'
  1829.                      '{\n'%(i.name_lower, i.camel_name))
  1830.         for p in i.properties:
  1831.             self.c.write('  iface->get_%s = %s_proxy_get_%s;\n'%(p.name_lower, i.name_lower, p.name_lower))
  1832.         self.c.write('}\n'
  1833.                      '\n')
  1834.  
  1835.         # constructors
  1836.         self.c.write(self.docbook_gen.expand(
  1837.                 '/**\n'
  1838.                 ' * %s_proxy_new:\n'
  1839.                 ' * @connection: A #GDBusConnection.\n'
  1840.                 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
  1841.                 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
  1842.                 ' * @object_path: An object path.\n'
  1843.                 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
  1844.                 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
  1845.                 ' * @user_data: User data to pass to @callback.\n'
  1846.                 ' *\n'
  1847.                 ' * Asynchronously creates a proxy for the D-Bus interface #%s. See g_dbus_proxy_new() for more details.\n'
  1848.                 ' *\n'
  1849.                 ' * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.\n'
  1850.                 ' * You can then call %s_proxy_new_finish() to get the result of the operation.\n'
  1851.                 ' *\n'
  1852.                 ' * See %s_proxy_new_sync() for the synchronous, blocking version of this constructor.\n'
  1853.                 %(i.name_lower, i.name, i.name_lower, i.name_lower), False))
  1854.         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
  1855.         self.c.write('void\n'
  1856.                      '%s_proxy_new (\n'
  1857.                      '    GDBusConnection     *connection,\n'
  1858.                      '    GDBusProxyFlags      flags,\n'
  1859.                      '    const gchar         *name,\n'
  1860.                      '    const gchar         *object_path,\n'
  1861.                      '    GCancellable        *cancellable,\n'
  1862.                      '    GAsyncReadyCallback  callback,\n'
  1863.                      '    gpointer             user_data)\n'
  1864.                      '{\n'
  1865.                      '  g_async_initable_new_async (%sTYPE_%s_PROXY, G_PRIORITY_DEFAULT, cancellable, callback, user_data, "g-flags", flags, "g-name", name, "g-connection", connection, "g-object-path", object_path, "g-interface-name", "%s", NULL);\n'
  1866.                      '}\n'
  1867.                      '\n'
  1868.                      %(i.name_lower, i.ns_upper, i.name_upper, i.name))
  1869.         self.c.write('/**\n'
  1870.                      ' * %s_proxy_new_finish:\n'
  1871.                      ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_proxy_new().\n'
  1872.                      ' * @error: Return location for error or %%NULL\n'
  1873.                      ' *\n'
  1874.                      ' * Finishes an operation started with %s_proxy_new().\n'
  1875.                      ' *\n'
  1876.                      ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
  1877.                      %(i.name_lower, i.name_lower, i.name_lower, i.camel_name))
  1878.         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
  1879.         self.c.write('%s *\n'
  1880.                      '%s_proxy_new_finish (\n'
  1881.                      '    GAsyncResult        *res,\n'
  1882.                      '    GError             **error)\n'
  1883.                      '{\n'
  1884.                      '  GObject *ret;\n'
  1885.                      '  GObject *source_object;\n'
  1886.                      '  source_object = g_async_result_get_source_object (res);\n'
  1887.                      '  ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
  1888.                      '  g_object_unref (source_object);\n'
  1889.                      '  if (ret != NULL)\n'
  1890.                      '    return %s%s (ret);\n'
  1891.                      '  else\n'
  1892.                      '    return NULL;\n'
  1893.                      '}\n'
  1894.                      '\n'
  1895.                      %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper))
  1896.         self.c.write(self.docbook_gen.expand(
  1897.                 '/**\n'
  1898.                 ' * %s_proxy_new_sync:\n'
  1899.                 ' * @connection: A #GDBusConnection.\n'
  1900.                 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
  1901.                 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
  1902.                 ' * @object_path: An object path.\n'
  1903.                 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
  1904.                 ' * @error: Return location for error or %%NULL\n'
  1905.                 ' *\n'
  1906.                 ' * Synchronously creates a proxy for the D-Bus interface #%s. See g_dbus_proxy_new_sync() for more details.\n'
  1907.                 ' *\n'
  1908.                 ' * The calling thread is blocked until a reply is received.\n'
  1909.                 ' *\n'
  1910.                 ' * See %s_proxy_new() for the asynchronous version of this constructor.\n'
  1911.                 ' *\n'
  1912.                 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
  1913.                 %(i.name_lower, i.name, i.name_lower, i.camel_name), False))
  1914.         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
  1915.         self.c.write('%s *\n'
  1916.                      '%s_proxy_new_sync (\n'
  1917.                      '    GDBusConnection     *connection,\n'
  1918.                      '    GDBusProxyFlags      flags,\n'
  1919.                      '    const gchar         *name,\n'
  1920.                      '    const gchar         *object_path,\n'
  1921.                      '    GCancellable        *cancellable,\n'
  1922.                      '    GError             **error)\n'
  1923.                      '{\n'
  1924.                      '  GInitable *ret;\n'
  1925.                      '  ret = g_initable_new (%sTYPE_%s_PROXY, cancellable, error, "g-flags", flags, "g-name", name, "g-connection", connection, "g-object-path", object_path, "g-interface-name", "%s", NULL);\n'
  1926.                      '  if (ret != NULL)\n'
  1927.                      '    return %s%s (ret);\n'
  1928.                      '  else\n'
  1929.                      '    return NULL;\n'
  1930.                      '}\n'
  1931.                      '\n'
  1932.                      %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.name, i.ns_upper, i.name_upper))
  1933.         self.c.write('\n')
  1934.         self.c.write(self.docbook_gen.expand(
  1935.                 '/**\n'
  1936.                 ' * %s_proxy_new_for_bus:\n'
  1937.                 ' * @bus_type: A #GBusType.\n'
  1938.                 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
  1939.                 ' * @name: A bus name (well-known or unique).\n'
  1940.                 ' * @object_path: An object path.\n'
  1941.                 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
  1942.                 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
  1943.                 ' * @user_data: User data to pass to @callback.\n'
  1944.                 ' *\n'
  1945.                 ' * Like %s_proxy_new() but takes a #GBusType instead of a #GDBusConnection.\n'
  1946.                 ' *\n'
  1947.                 ' * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.\n'
  1948.                 ' * You can then call %s_proxy_new_for_bus_finish() to get the result of the operation.\n'
  1949.                 ' *\n'
  1950.                 ' * See %s_proxy_new_for_bus_sync() for the synchronous, blocking version of this constructor.\n'
  1951.                 %(i.name_lower, i.name_lower, i.name_lower, i.name_lower), False))
  1952.         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
  1953.         self.c.write('void\n'
  1954.                      '%s_proxy_new_for_bus (\n'
  1955.                      '    GBusType             bus_type,\n'
  1956.                      '    GDBusProxyFlags      flags,\n'
  1957.                      '    const gchar         *name,\n'
  1958.                      '    const gchar         *object_path,\n'
  1959.                      '    GCancellable        *cancellable,\n'
  1960.                      '    GAsyncReadyCallback  callback,\n'
  1961.                      '    gpointer             user_data)\n'
  1962.                      '{\n'
  1963.                      '  g_async_initable_new_async (%sTYPE_%s_PROXY, G_PRIORITY_DEFAULT, cancellable, callback, user_data, "g-flags", flags, "g-name", name, "g-bus-type", bus_type, "g-object-path", object_path, "g-interface-name", "%s", NULL);\n'
  1964.                      '}\n'
  1965.                      '\n'
  1966.                      %(i.name_lower, i.ns_upper, i.name_upper, i.name))
  1967.         self.c.write('/**\n'
  1968.                      ' * %s_proxy_new_for_bus_finish:\n'
  1969.                      ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %s_proxy_new_for_bus().\n'
  1970.                      ' * @error: Return location for error or %%NULL\n'
  1971.                      ' *\n'
  1972.                      ' * Finishes an operation started with %s_proxy_new_for_bus().\n'
  1973.                      ' *\n'
  1974.                      ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
  1975.                      %(i.name_lower, i.name_lower, i.name_lower, i.camel_name))
  1976.         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
  1977.         self.c.write('%s *\n'
  1978.                      '%s_proxy_new_for_bus_finish (\n'
  1979.                      '    GAsyncResult        *res,\n'
  1980.                      '    GError             **error)\n'
  1981.                      '{\n'
  1982.                      '  GObject *ret;\n'
  1983.                      '  GObject *source_object;\n'
  1984.                      '  source_object = g_async_result_get_source_object (res);\n'
  1985.                      '  ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
  1986.                      '  g_object_unref (source_object);\n'
  1987.                      '  if (ret != NULL)\n'
  1988.                      '    return %s%s (ret);\n'
  1989.                      '  else\n'
  1990.                      '    return NULL;\n'
  1991.                      '}\n'
  1992.                      '\n'
  1993.                      %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper))
  1994.         self.c.write(self.docbook_gen.expand(
  1995.                 '/**\n'
  1996.                 ' * %s_proxy_new_for_bus_sync:\n'
  1997.                 ' * @bus_type: A #GBusType.\n'
  1998.                 ' * @flags: Flags from the #GDBusProxyFlags enumeration.\n'
  1999.                 ' * @name: A bus name (well-known or unique).\n'
  2000.                 ' * @object_path: An object path.\n'
  2001.                 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
  2002.                 ' * @error: Return location for error or %%NULL\n'
  2003.                 ' *\n'
  2004.                 ' * Like %s_proxy_new_sync() but takes a #GBusType instead of a #GDBusConnection.\n'
  2005.                 ' *\n'
  2006.                 ' * The calling thread is blocked until a reply is received.\n'
  2007.                 ' *\n'
  2008.                 ' * See %s_proxy_new_for_bus() for the asynchronous version of this constructor.\n'
  2009.                 ' *\n'
  2010.                 ' * Returns: (transfer full) (type %sProxy): The constructed proxy object or %%NULL if @error is set.\n'
  2011.                 %(i.name_lower, i.name_lower, i.name_lower, i.camel_name), False))
  2012.         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
  2013.         self.c.write('%s *\n'
  2014.                      '%s_proxy_new_for_bus_sync (\n'
  2015.                      '    GBusType             bus_type,\n'
  2016.                      '    GDBusProxyFlags      flags,\n'
  2017.                      '    const gchar         *name,\n'
  2018.                      '    const gchar         *object_path,\n'
  2019.                      '    GCancellable        *cancellable,\n'
  2020.                      '    GError             **error)\n'
  2021.                      '{\n'
  2022.                      '  GInitable *ret;\n'
  2023.                      '  ret = g_initable_new (%sTYPE_%s_PROXY, cancellable, error, "g-flags", flags, "g-name", name, "g-bus-type", bus_type, "g-object-path", object_path, "g-interface-name", "%s", NULL);\n'
  2024.                      '  if (ret != NULL)\n'
  2025.                      '    return %s%s (ret);\n'
  2026.                      '  else\n'
  2027.                      '    return NULL;\n'
  2028.                      '}\n'
  2029.                      '\n'
  2030.                      %(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.name, i.ns_upper, i.name_upper))
  2031.         self.c.write('\n')
  2032.  
  2033.     # ---------------------------------------------------------------------------------------------------
  2034.  
  2035.     def generate_skeleton(self, i):
  2036.         # class boilerplate
  2037.         self.c.write('/* ------------------------------------------------------------------------ */\n'
  2038.                      '\n')
  2039.  
  2040.         self.c.write(self.docbook_gen.expand(
  2041.                 '/**\n'
  2042.                 ' * %sSkeleton:\n'
  2043.                 ' *\n'
  2044.                 ' * The #%sSkeleton structure contains only private data and should only be accessed using the provided API.\n'
  2045.                 %(i.camel_name, i.camel_name), False))
  2046.         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
  2047.         self.c.write('\n')
  2048.  
  2049.         self.c.write(self.docbook_gen.expand(
  2050.                 '/**\n'
  2051.                 ' * %sSkeletonClass:\n'
  2052.                 ' * @parent_class: The parent class.\n'
  2053.                 ' *\n'
  2054.                 ' * Class structure for #%sSkeleton.\n'
  2055.                 %(i.camel_name, i.camel_name), False))
  2056.         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
  2057.         self.c.write('\n')
  2058.  
  2059.         self.c.write('struct _%sSkeletonPrivate\n'
  2060.                      '{\n'
  2061.                      '  GValue *properties;\n'
  2062.                      '  GList *changed_properties;\n'
  2063.                      '  GSource *changed_properties_idle_source;\n'
  2064.                      '  GMainContext *context;\n'
  2065.                      '  GMutex lock;\n'
  2066.                      '};\n'
  2067.                      '\n'%i.camel_name)
  2068.  
  2069.         self.c.write('static void\n'
  2070.                      '_%s_skeleton_handle_method_call (\n'
  2071.                      '  GDBusConnection *connection G_GNUC_UNUSED,\n'
  2072.                      '  const gchar *sender G_GNUC_UNUSED,\n'
  2073.                      '  const gchar *object_path G_GNUC_UNUSED,\n'
  2074.                      '  const gchar *interface_name,\n'
  2075.                      '  const gchar *method_name,\n'
  2076.                      '  GVariant *parameters,\n'
  2077.                      '  GDBusMethodInvocation *invocation,\n'
  2078.                      '  gpointer user_data)\n'
  2079.                      '{\n'
  2080.                      '  %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
  2081.                      '  _ExtendedGDBusMethodInfo *info;\n'
  2082.                      '  GVariantIter iter;\n'
  2083.                      '  GVariant *child;\n'
  2084.                      '  GValue *paramv;\n'
  2085.                      '  guint num_params;\n'
  2086.                      '  guint num_extra;\n'
  2087.                      '  guint n;\n'
  2088.                      '  guint signal_id;\n'
  2089.                      '  GValue return_value = G_VALUE_INIT;\n'
  2090.                      %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
  2091.         self.c.write('  info = (_ExtendedGDBusMethodInfo *) g_dbus_method_invocation_get_method_info (invocation);\n'
  2092.                      '  g_assert (info != NULL);\n'
  2093.                      %())
  2094.         self.c.write ('  num_params = g_variant_n_children (parameters);\n'
  2095.                       '  num_extra = info->pass_fdlist ? 3 : 2;'
  2096.                       '  paramv = g_new0 (GValue, num_params + num_extra);\n'
  2097.                       '  n = 0;\n'
  2098.                       '  g_value_init (¶mv[n], %sTYPE_%s);\n'
  2099.                       '  g_value_set_object (¶mv[n++], skeleton);\n'
  2100.                       '  g_value_init (¶mv[n], G_TYPE_DBUS_METHOD_INVOCATION);\n'
  2101.                       '  g_value_set_object (¶mv[n++], invocation);\n'
  2102.                       '  if (info->pass_fdlist)\n'
  2103.                       '    {\n'
  2104.                       '#ifdef G_OS_UNIX\n'
  2105.                       '      g_value_init (¶mv[n], G_TYPE_UNIX_FD_LIST);\n'
  2106.                       '      g_value_set_object (¶mv[n++], g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation)));\n'
  2107.                       '#else\n'
  2108.                       '      g_assert_not_reached ();\n'
  2109.                       '#endif\n'
  2110.                       '    }\n'
  2111.                       %(i.ns_upper, i.name_upper))
  2112.         self.c.write('  g_variant_iter_init (&iter, parameters);\n'
  2113.                      '  while ((child = g_variant_iter_next_value (&iter)) != NULL)\n'
  2114.                      '    {\n'
  2115.                      '      _ExtendedGDBusArgInfo *arg_info = (_ExtendedGDBusArgInfo *) info->parent_struct.in_args[n - num_extra];\n'
  2116.                      '      if (arg_info->use_gvariant)\n'
  2117.                      '        {\n'
  2118.                      '          g_value_init (¶mv[n], G_TYPE_VARIANT);\n'
  2119.                      '          g_value_set_variant (¶mv[n], child);\n'
  2120.                      '          n++;\n'
  2121.                      '        }\n'
  2122.                      '      else\n'
  2123.                      '        g_dbus_gvariant_to_gvalue (child, ¶mv[n++]);\n'
  2124.                      '      g_variant_unref (child);\n'
  2125.                      '    }\n'
  2126.                      )
  2127.         self.c.write('  signal_id = g_signal_lookup (info->signal_name, %sTYPE_%s);\n'
  2128.                      %(i.ns_upper, i.name_upper))
  2129.         self.c.write('  g_value_init (&return_value, G_TYPE_BOOLEAN);\n'
  2130.                      '  g_signal_emitv (paramv, signal_id, 0, &return_value);\n'
  2131.                      '  if (!g_value_get_boolean (&return_value))\n'
  2132.                      '    g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, "Method %s is not implemented on interface %s", method_name, interface_name);\n'
  2133.                      '  g_value_unset (&return_value);\n'
  2134.                      )
  2135.         self.c.write('  for (n = 0; n < num_params + num_extra; n++)\n'
  2136.                      '    g_value_unset (¶mv[n]);\n'
  2137.                      '  g_free (paramv);\n')
  2138.         self.c.write('}\n'
  2139.                      '\n')
  2140.  
  2141.         self.c.write('static GVariant *\n'
  2142.                      '_%s_skeleton_handle_get_property (\n'
  2143.                      '  GDBusConnection *connection G_GNUC_UNUSED,\n'
  2144.                      '  const gchar *sender G_GNUC_UNUSED,\n'
  2145.                      '  const gchar *object_path G_GNUC_UNUSED,\n'
  2146.                      '  const gchar *interface_name G_GNUC_UNUSED,\n'
  2147.                      '  const gchar *property_name,\n'
  2148.                      '  GError **error,\n'
  2149.                      '  gpointer user_data)\n'
  2150.                      '{\n'
  2151.                      '  %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
  2152.                      '  GValue value = G_VALUE_INIT;\n'
  2153.                      '  GParamSpec *pspec;\n'
  2154.                      '  _ExtendedGDBusPropertyInfo *info;\n'
  2155.                      '  GVariant *ret;\n'
  2156.                      %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
  2157.         self.c.write('  ret = NULL;\n'
  2158.                      '  info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, property_name);\n'
  2159.                      '  g_assert (info != NULL);\n'
  2160.                      '  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name);\n'
  2161.                      '  if (pspec == NULL)\n'
  2162.                      '    {\n'
  2163.                      '      g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %%s", property_name);\n'
  2164.                      '    }\n'
  2165.                      '  else\n'
  2166.                      '    {\n'
  2167.                      '      g_value_init (&value, pspec->value_type);\n'
  2168.                      '      g_object_get_property (G_OBJECT (skeleton), info->hyphen_name, &value);\n'
  2169.                      '      ret = g_dbus_gvalue_to_gvariant (&value, G_VARIANT_TYPE (info->parent_struct.signature));\n'
  2170.                      '      g_value_unset (&value);\n'
  2171.                      '    }\n'
  2172.                      '  return ret;\n'
  2173.                      '}\n'
  2174.                      '\n'
  2175.                      %(i.name_lower))
  2176.  
  2177.         self.c.write('static gboolean\n'
  2178.                      '_%s_skeleton_handle_set_property (\n'
  2179.                      '  GDBusConnection *connection G_GNUC_UNUSED,\n'
  2180.                      '  const gchar *sender G_GNUC_UNUSED,\n'
  2181.                      '  const gchar *object_path G_GNUC_UNUSED,\n'
  2182.                      '  const gchar *interface_name G_GNUC_UNUSED,\n'
  2183.                      '  const gchar *property_name,\n'
  2184.                      '  GVariant *variant,\n'
  2185.                      '  GError **error,\n'
  2186.                      '  gpointer user_data)\n'
  2187.                      '{\n'
  2188.                      '  %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
  2189.                      '  GValue value = G_VALUE_INIT;\n'
  2190.                      '  GParamSpec *pspec;\n'
  2191.                      '  _ExtendedGDBusPropertyInfo *info;\n'
  2192.                      '  gboolean ret;\n'
  2193.                      %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
  2194.         self.c.write('  ret = FALSE;\n'
  2195.                      '  info = (_ExtendedGDBusPropertyInfo *) g_dbus_interface_info_lookup_property ((GDBusInterfaceInfo *) &_%s_interface_info.parent_struct, property_name);\n'
  2196.                      '  g_assert (info != NULL);\n'
  2197.                      '  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (skeleton), info->hyphen_name);\n'
  2198.                      '  if (pspec == NULL)\n'
  2199.                      '    {\n'
  2200.                      '      g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "No property with name %%s", property_name);\n'
  2201.                      '    }\n'
  2202.                      '  else\n'
  2203.                      '    {\n'
  2204.                      '      if (info->use_gvariant)\n'
  2205.                      '        g_value_set_variant (&value, variant);\n'
  2206.                      '      else\n'
  2207.                      '        g_dbus_gvariant_to_gvalue (variant, &value);\n'
  2208.                      '      g_object_set_property (G_OBJECT (skeleton), info->hyphen_name, &value);\n'
  2209.                      '      g_value_unset (&value);\n'
  2210.                      '      ret = TRUE;\n'
  2211.                      '    }\n'
  2212.                      '  return ret;\n'
  2213.                      '}\n'
  2214.                      '\n'
  2215.                      %(i.name_lower))
  2216.  
  2217.  
  2218.         self.c.write('static const GDBusInterfaceVTable _%s_skeleton_vtable =\n'
  2219.                      '{\n'
  2220.                      '  _%s_skeleton_handle_method_call,\n'
  2221.                      '  _%s_skeleton_handle_get_property,\n'
  2222.                      '  _%s_skeleton_handle_set_property,\n'
  2223.                      '  {NULL}\n'
  2224.                      '};\n'
  2225.                      '\n'%(i.name_lower, i.name_lower, i.name_lower, i.name_lower))
  2226.  
  2227.         self.c.write('static GDBusInterfaceInfo *\n'
  2228.                      '%s_skeleton_dbus_interface_get_info (GDBusInterfaceSkeleton *skeleton G_GNUC_UNUSED)\n'
  2229.                      '{\n'
  2230.                      '  return %s_interface_info ();\n'
  2231.                      %(i.name_lower, i.name_lower))
  2232.         self.c.write('}\n'
  2233.                      '\n')
  2234.  
  2235.         self.c.write('static GDBusInterfaceVTable *\n'
  2236.                      '%s_skeleton_dbus_interface_get_vtable (GDBusInterfaceSkeleton *skeleton G_GNUC_UNUSED)\n'
  2237.                      '{\n'
  2238.                      '  return (GDBusInterfaceVTable *) &_%s_skeleton_vtable;\n'
  2239.                      %(i.name_lower, i.name_lower))
  2240.         self.c.write('}\n'
  2241.                      '\n')
  2242.  
  2243.         self.c.write('static GVariant *\n'
  2244.                      '%s_skeleton_dbus_interface_get_properties (GDBusInterfaceSkeleton *_skeleton)\n'
  2245.                      '{\n'
  2246.                      '  %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
  2247.                      %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
  2248.         self.c.write('\n'
  2249.                      '  GVariantBuilder builder;\n'
  2250.                      '  guint n;\n'
  2251.                      '  g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
  2252.                      '  if (_%s_interface_info.parent_struct.properties == NULL)\n'
  2253.                      '    goto out;\n'
  2254.                      '  for (n = 0; _%s_interface_info.parent_struct.properties[n] != NULL; n++)\n'
  2255.                      '    {\n'
  2256.                      '      GDBusPropertyInfo *info = _%s_interface_info.parent_struct.properties[n];\n'
  2257.                      '      if (info->flags & G_DBUS_PROPERTY_INFO_FLAGS_READABLE)\n'
  2258.                      '        {\n'
  2259.                      '          GVariant *value;\n'
  2260.                      '          value = _%s_skeleton_handle_get_property (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)), NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), "%s", info->name, NULL, skeleton);\n'
  2261.                      '          if (value != NULL)\n'
  2262.                      '            {\n'
  2263.                      '              g_variant_take_ref (value);\n'
  2264.                      '              g_variant_builder_add (&builder, "{sv}", info->name, value);\n'
  2265.                      '              g_variant_unref (value);\n'
  2266.                      '            }\n'
  2267.                      '        }\n'
  2268.                      '    }\n'
  2269.                      'out:\n'
  2270.                      '  return g_variant_builder_end (&builder);\n'
  2271.                      '}\n'
  2272.                      '\n'
  2273.                      %(i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name))
  2274.  
  2275.         if len(i.properties) > 0:
  2276.             self.c.write('static gboolean _%s_emit_changed (gpointer user_data);\n'
  2277.                          '\n'
  2278.                          %(i.name_lower))
  2279.  
  2280.         self.c.write('static void\n'
  2281.                      '%s_skeleton_dbus_interface_flush (GDBusInterfaceSkeleton *_skeleton)\n'
  2282.                      '{\n'
  2283.                      %(i.name_lower))
  2284.         if len(i.properties) > 0:
  2285.             self.c.write('  %sSkeleton *skeleton = %s%s_SKELETON (_skeleton);\n'
  2286.                          '  gboolean emit_changed = FALSE;\n'
  2287.                          '\n'
  2288.                          '  g_mutex_lock (&skeleton->priv->lock);\n'
  2289.                          '  if (skeleton->priv->changed_properties_idle_source != NULL)\n'
  2290.                          '    {\n'
  2291.                          '      g_source_destroy (skeleton->priv->changed_properties_idle_source);\n'
  2292.                          '      skeleton->priv->changed_properties_idle_source = NULL;\n'
  2293.                          '      emit_changed = TRUE;\n'
  2294.                          '    }\n'
  2295.                          '  g_mutex_unlock (&skeleton->priv->lock);\n'
  2296.                          '\n'
  2297.                          '  if (emit_changed)\n'
  2298.                          '    _%s_emit_changed (skeleton);\n'
  2299.                          %(i.camel_name, i.ns_upper, i.name_upper, i.name_lower))
  2300.         self.c.write('}\n'
  2301.                      '\n')
  2302.  
  2303.         for s in i.signals:
  2304.             self.c.write('static void\n'
  2305.                          '_%s_on_signal_%s (\n'
  2306.                          '    %s *object'%(i.name_lower, s.name_lower, i.camel_name))
  2307.             for a in s.args:
  2308.                 self.c.write(',\n    %sarg_%s'%(a.ctype_in, a.name))
  2309.             self.c.write(')\n'
  2310.                          '{\n'
  2311.                          '  %sSkeleton *skeleton = %s%s_SKELETON (object);\n\n'
  2312.                          '  GList      *connections, *l;\n'
  2313.                          '  GVariant   *signal_variant;\n'
  2314.                          '  connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton));\n'
  2315.                          %(i.camel_name, i.ns_upper, i.name_upper))
  2316.             self.c.write('\n'
  2317.                          '  signal_variant = g_variant_ref_sink (g_variant_new ("(')
  2318.             for a in s.args:
  2319.                 self.c.write('%s'%(a.format_in))
  2320.             self.c.write(')"')
  2321.             for a in s.args:
  2322.                 self.c.write(',\n                   arg_%s'%(a.name))
  2323.             self.c.write('));\n')
  2324.  
  2325.             self.c.write('  for (l = connections; l != NULL; l = l->next)\n'
  2326.                          '    {\n'
  2327.                          '      GDBusConnection *connection = l->data;\n'
  2328.                          '      g_dbus_connection_emit_signal (connection,\n'
  2329.                          '        NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), "%s", "%s",\n'
  2330.                          '        signal_variant, NULL);\n'
  2331.                          '    }\n'
  2332.                          %(i.name, s.name))
  2333.             self.c.write('  g_variant_unref (signal_variant);\n')
  2334.             self.c.write('  g_list_free_full (connections, g_object_unref);\n')
  2335.             self.c.write('}\n'
  2336.                          '\n')
  2337.  
  2338.         self.c.write('static void %s_skeleton_iface_init (%sIface *iface);\n'
  2339.                      %(i.name_lower, i.camel_name))
  2340.  
  2341.         self.c.write('G_DEFINE_TYPE_WITH_CODE (%sSkeleton, %s_skeleton, G_TYPE_DBUS_INTERFACE_SKELETON,\n'%(i.camel_name, i.name_lower))
  2342.         self.c.write('                         G_ADD_PRIVATE (%sSkeleton)\n'%(i.camel_name))
  2343.         self.c.write('                         G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_skeleton_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
  2344.  
  2345.         # finalize
  2346.         self.c.write('static void\n'
  2347.                      '%s_skeleton_finalize (GObject *object)\n'
  2348.                      '{\n'%(i.name_lower))
  2349.         self.c.write('  %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
  2350.         if len(i.properties) > 0:
  2351.             self.c.write('  guint n;\n'
  2352.                          '  for (n = 0; n < %d; n++)\n'
  2353.                          '    g_value_unset (&skeleton->priv->properties[n]);\n'%(len(i.properties)))
  2354.             self.c.write('  g_free (skeleton->priv->properties);\n')
  2355.         self.c.write('  g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free);\n')
  2356.         self.c.write('  if (skeleton->priv->changed_properties_idle_source != NULL)\n')
  2357.         self.c.write('    g_source_destroy (skeleton->priv->changed_properties_idle_source);\n')
  2358.         self.c.write('  g_main_context_unref (skeleton->priv->context);\n')
  2359.         self.c.write('  g_mutex_clear (&skeleton->priv->lock);\n')
  2360.         self.c.write('  G_OBJECT_CLASS (%s_skeleton_parent_class)->finalize (object);\n'
  2361.                      '}\n'
  2362.                      '\n'%(i.name_lower))
  2363.  
  2364.         # property accessors (TODO: generate PropertiesChanged signals in setter)
  2365.         if len(i.properties) > 0:
  2366.             self.c.write('static void\n'
  2367.                          '%s_skeleton_get_property (GObject      *object,\n'
  2368.                          '  guint         prop_id,\n'
  2369.                          '  GValue       *value,\n'
  2370.                          '  GParamSpec   *pspec G_GNUC_UNUSED)\n'
  2371.                          '{\n'%(i.name_lower))
  2372.             self.c.write('  %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
  2373.                          '  g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
  2374.                          '  g_mutex_lock (&skeleton->priv->lock);\n'
  2375.                          '  g_value_copy (&skeleton->priv->properties[prop_id - 1], value);\n'
  2376.                          '  g_mutex_unlock (&skeleton->priv->lock);\n'
  2377.                          %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties)))
  2378.             self.c.write('}\n'
  2379.                          '\n')
  2380.  
  2381.             # if property is already scheduled then re-use entry.. though it could be
  2382.             # that the user did
  2383.             #
  2384.             #  foo_set_prop_bar (object, "");
  2385.             #  foo_set_prop_bar (object, "blah");
  2386.             #
  2387.             # say, every update... In this case, where nothing happens, we obviously
  2388.             # don't want a PropertiesChanged() event. We can easily check for this
  2389.             # by comparing against the _original value_ recorded before the first
  2390.             # change event. If the latest value is not different from the original
  2391.             # one, we can simply ignore the ChangedProperty
  2392.             #
  2393.             self.c.write('static gboolean\n'
  2394.                          '_%s_emit_changed (gpointer user_data)\n'
  2395.                          '{\n'
  2396.                          '  %sSkeleton *skeleton = %s%s_SKELETON (user_data);\n'
  2397.                          %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper))
  2398.             self.c.write('  GList *l;\n'
  2399.                          '  GVariantBuilder builder;\n'
  2400.                          '  GVariantBuilder invalidated_builder;\n'
  2401.                          '  guint num_changes;\n'
  2402.                          '\n'
  2403.                          '  g_mutex_lock (&skeleton->priv->lock);\n'
  2404.                          '  g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));\n'
  2405.                          '  g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ("as"));\n'
  2406.                          '  for (l = skeleton->priv->changed_properties, num_changes = 0; l != NULL; l = l->next)\n'
  2407.                          '    {\n'
  2408.                          '      ChangedProperty *cp = l->data;\n'
  2409.                          '      GVariant *variant;\n'
  2410.                          '      const GValue *cur_value;\n'
  2411.                          '\n'
  2412.                          '      cur_value = &skeleton->priv->properties[cp->prop_id - 1];\n'
  2413.                          '      if (!_g_value_equal (cur_value, &cp->orig_value))\n'
  2414.                          '        {\n'
  2415.                          '          variant = g_dbus_gvalue_to_gvariant (cur_value, G_VARIANT_TYPE (cp->info->parent_struct.signature));\n'
  2416.                          '          g_variant_builder_add (&builder, "{sv}", cp->info->parent_struct.name, variant);\n'
  2417.                          '          g_variant_unref (variant);\n'
  2418.                          '          num_changes++;\n'
  2419.                          '        }\n'
  2420.                          '    }\n'
  2421.                          '  if (num_changes > 0)\n'
  2422.                          '    {\n'
  2423.                          '      GList *connections, *ll;\n'
  2424.                          '      GVariant *signal_variant;'
  2425.                          '\n'
  2426.                          '      signal_variant = g_variant_ref_sink (g_variant_new ("(sa{sv}as)", "%s",\n'
  2427.                          '                                           &builder, &invalidated_builder));\n'
  2428.                          '      connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton));\n'
  2429.                          '      for (ll = connections; ll != NULL; ll = ll->next)\n'
  2430.                          '        {\n'
  2431.                          '          GDBusConnection *connection = ll->data;\n'
  2432.                          '\n'
  2433.                          '          g_dbus_connection_emit_signal (connection,\n'
  2434.                          '                                         NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)),\n'
  2435.                          '                                         "org.freedesktop.DBus.Properties",\n'
  2436.                          '                                         "PropertiesChanged",\n'
  2437.                          '                                         signal_variant,\n'
  2438.                          '                                         NULL);\n'
  2439.                          '        }\n'
  2440.                          '      g_variant_unref (signal_variant);\n'
  2441.                          '      g_list_free_full (connections, g_object_unref);\n'
  2442.                          '    }\n'
  2443.                          '  else\n'
  2444.                          '    {\n'
  2445.                          '      g_variant_builder_clear (&builder);\n'
  2446.                          '      g_variant_builder_clear (&invalidated_builder);\n'
  2447.                          '    }\n'
  2448.                          %(i.name))
  2449.             self.c.write('  g_list_free_full (skeleton->priv->changed_properties, (GDestroyNotify) _changed_property_free);\n')
  2450.             self.c.write('  skeleton->priv->changed_properties = NULL;\n')
  2451.             self.c.write('  skeleton->priv->changed_properties_idle_source = NULL;\n')
  2452.             self.c.write('  g_mutex_unlock (&skeleton->priv->lock);\n')
  2453.             self.c.write('  return FALSE;\n'
  2454.                          '}\n'
  2455.                          '\n')
  2456.             # holding lock while being called
  2457.             self.c.write('static void\n'
  2458.                          '_%s_schedule_emit_changed (%sSkeleton *skeleton, const _ExtendedGDBusPropertyInfo *info, guint prop_id, const GValue *orig_value)\n'
  2459.                          '{\n'
  2460.                          '  ChangedProperty *cp;\n'
  2461.                          '  GList *l;\n'
  2462.                          '  cp = NULL;\n'
  2463.                          '  for (l = skeleton->priv->changed_properties; l != NULL; l = l->next)\n'
  2464.                          '    {\n'
  2465.                          '      ChangedProperty *i_cp = l->data;\n'
  2466.                          '      if (i_cp->info == info)\n'
  2467.                          '        {\n'
  2468.                          '          cp = i_cp;\n'
  2469.                          '          break;\n'
  2470.                          '        }\n'
  2471.                          '    }\n'
  2472.                          %(i.name_lower, i.camel_name))
  2473.             self.c.write('  if (cp == NULL)\n'
  2474.                          '    {\n'
  2475.                          '      cp = g_new0 (ChangedProperty, 1);\n'
  2476.                          '      cp->prop_id = prop_id;\n'
  2477.                          '      cp->info = info;\n'
  2478.                          '      skeleton->priv->changed_properties = g_list_prepend (skeleton->priv->changed_properties, cp);\n'
  2479.                          '      g_value_init (&cp->orig_value, G_VALUE_TYPE (orig_value));\n'
  2480.                          '      g_value_copy (orig_value, &cp->orig_value);\n'
  2481.                          '    }\n'
  2482.                          '}\n'
  2483.                          '\n'
  2484.                          %())
  2485.  
  2486.             # Postpone setting up the refresh source until the ::notify signal is emitted as
  2487.             # this allows use of g_object_freeze_notify()/g_object_thaw_notify() ...
  2488.             # This is useful when updating several properties from another thread than
  2489.             # where the idle will be emitted from
  2490.             self.c.write('static void\n'
  2491.                          '%s_skeleton_notify (GObject      *object,\n'
  2492.                          '  GParamSpec *pspec G_GNUC_UNUSED)\n'
  2493.                          '{\n'
  2494.                          '  %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
  2495.                          '  g_mutex_lock (&skeleton->priv->lock);\n'
  2496.                          '  if (skeleton->priv->changed_properties != NULL &&\n'
  2497.                          '      skeleton->priv->changed_properties_idle_source == NULL)\n'
  2498.                          '    {\n'
  2499.                          '      skeleton->priv->changed_properties_idle_source = g_idle_source_new ();\n'
  2500.                          '      g_source_set_priority (skeleton->priv->changed_properties_idle_source, G_PRIORITY_DEFAULT);\n'
  2501.                          '      g_source_set_callback (skeleton->priv->changed_properties_idle_source, _%s_emit_changed, g_object_ref (skeleton), (GDestroyNotify) g_object_unref);\n'
  2502.                          '      g_source_attach (skeleton->priv->changed_properties_idle_source, skeleton->priv->context);\n'
  2503.                          '      g_source_unref (skeleton->priv->changed_properties_idle_source);\n'
  2504.                          '    }\n'
  2505.                          '  g_mutex_unlock (&skeleton->priv->lock);\n'
  2506.                          '}\n'
  2507.                          '\n'
  2508.                          %(i.name_lower, i.camel_name, i.ns_upper, i.name_upper, i.name_lower))
  2509.  
  2510.             self.c.write('static void\n'
  2511.                          '%s_skeleton_set_property (GObject      *object,\n'
  2512.                          '  guint         prop_id,\n'
  2513.                          '  const GValue *value,\n'
  2514.                          '  GParamSpec   *pspec)\n'
  2515.                          '{\n'%(i.name_lower))
  2516.             self.c.write('  %sSkeleton *skeleton = %s%s_SKELETON (object);\n'
  2517.                          '  g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
  2518.                          '  g_mutex_lock (&skeleton->priv->lock);\n'
  2519.                          '  g_object_freeze_notify (object);\n'
  2520.                          '  if (!_g_value_equal (value, &skeleton->priv->properties[prop_id - 1]))\n'
  2521.                          '    {\n'
  2522.                          '      if (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)) != NULL)\n'
  2523.                          '        _%s_schedule_emit_changed (skeleton, _%s_property_info_pointers[prop_id - 1], prop_id, &skeleton->priv->properties[prop_id - 1]);\n'
  2524.                          '      g_value_copy (value, &skeleton->priv->properties[prop_id - 1]);\n'
  2525.                          '      g_object_notify_by_pspec (object, pspec);\n'
  2526.                          '    }\n'
  2527.                          '  g_mutex_unlock (&skeleton->priv->lock);\n'
  2528.                          '  g_object_thaw_notify (object);\n'
  2529.                          %(i.camel_name, i.ns_upper, i.name_upper, len(i.properties), i.name_lower, i.name_lower))
  2530.             self.c.write('}\n'
  2531.                          '\n')
  2532.  
  2533.         self.c.write('static void\n'
  2534.                      '%s_skeleton_init (%sSkeleton *skeleton)\n'
  2535.                      '{\n'
  2536.                      '  skeleton->priv = %s_skeleton_get_instance_private (skeleton);\n'
  2537.                      %(i.name_lower, i.camel_name,
  2538.                        i.name_lower))
  2539.         self.c.write('  g_mutex_init (&skeleton->priv->lock);\n')
  2540.         self.c.write('  skeleton->priv->context = g_main_context_ref_thread_default ();\n')
  2541.         if len(i.properties) > 0:
  2542.             self.c.write('  skeleton->priv->properties = g_new0 (GValue, %d);\n'%(len(i.properties)))
  2543.             n = 0
  2544.             for p in i.properties:
  2545.                 self.c.write('  g_value_init (&skeleton->priv->properties[%d], %s);\n'%(n, p.arg.gtype))
  2546.                 n += 1
  2547.         self.c.write('}\n'
  2548.                      '\n')
  2549.  
  2550.         # property vfuncs
  2551.         n = 0
  2552.         for p in i.properties:
  2553.             self.c.write('static %s\n'
  2554.                          '%s_skeleton_get_%s (%s *object)\n'
  2555.                          '{\n'
  2556.                          %(p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name))
  2557.             self.c.write('  %sSkeleton *skeleton = %s%s_SKELETON (object);\n'%(i.camel_name, i.ns_upper, i.name_upper))
  2558.             self.c.write('  %svalue;\n'
  2559.                          '  g_mutex_lock (&skeleton->priv->lock);\n'
  2560.                          '  value = %s (&(skeleton->priv->properties[%d]));\n'
  2561.                          '  g_mutex_unlock (&skeleton->priv->lock);\n'
  2562.                          %(p.arg.ctype_in_g, p.arg.gvalue_get, n))
  2563.             self.c.write('  return value;\n')
  2564.             self.c.write('}\n')
  2565.             self.c.write('\n')
  2566.             n += 1
  2567.  
  2568.         self.c.write('static void\n'
  2569.                      '%s_skeleton_class_init (%sSkeletonClass *klass)\n'
  2570.                      '{\n'
  2571.                      '  GObjectClass *gobject_class;\n'
  2572.                      '  GDBusInterfaceSkeletonClass *skeleton_class;\n'
  2573.                      '\n'
  2574.                      '  gobject_class = G_OBJECT_CLASS (klass);\n'
  2575.                      '  gobject_class->finalize = %s_skeleton_finalize;\n'
  2576.                      %(i.name_lower, i.camel_name, i.name_lower))
  2577.         if len(i.properties) > 0:
  2578.             self.c.write('  gobject_class->get_property = %s_skeleton_get_property;\n'
  2579.                          '  gobject_class->set_property = %s_skeleton_set_property;\n'
  2580.                          '  gobject_class->notify       = %s_skeleton_notify;\n'
  2581.                          '\n'%(i.name_lower, i.name_lower, i.name_lower))
  2582.             self.c.write('\n'
  2583.                          '  %s_override_properties (gobject_class, 1);\n'%(i.name_lower))
  2584.         self.c.write('\n'
  2585.                      '  skeleton_class = G_DBUS_INTERFACE_SKELETON_CLASS (klass);\n');
  2586.         self.c.write('  skeleton_class->get_info = %s_skeleton_dbus_interface_get_info;\n'%(i.name_lower))
  2587.         self.c.write('  skeleton_class->get_properties = %s_skeleton_dbus_interface_get_properties;\n'%(i.name_lower))
  2588.         self.c.write('  skeleton_class->flush = %s_skeleton_dbus_interface_flush;\n'%(i.name_lower))
  2589.         self.c.write('  skeleton_class->get_vtable = %s_skeleton_dbus_interface_get_vtable;\n'%(i.name_lower))
  2590.         self.c.write('}\n'
  2591.                      '\n')
  2592.  
  2593.         self.c.write('static void\n'
  2594.                      '%s_skeleton_iface_init (%sIface *iface)\n'
  2595.                      '{\n'
  2596.                      %(i.name_lower, i.camel_name))
  2597.         for s in i.signals:
  2598.             self.c.write('  iface->%s = _%s_on_signal_%s;\n'
  2599.                          %(s.name_lower, i.name_lower, s.name_lower))
  2600.         for p in i.properties:
  2601.             self.c.write('  iface->get_%s = %s_skeleton_get_%s;\n'%(p.name_lower, i.name_lower, p.name_lower))
  2602.         self.c.write('}\n'
  2603.                      '\n')
  2604.  
  2605.         # constructors
  2606.         self.c.write(self.docbook_gen.expand(
  2607.                 '/**\n'
  2608.                 ' * %s_skeleton_new:\n'
  2609.                 ' *\n'
  2610.                 ' * Creates a skeleton object for the D-Bus interface #%s.\n'
  2611.                 ' *\n'
  2612.                 ' * Returns: (transfer full) (type %sSkeleton): The skeleton object.\n'
  2613.                 %(i.name_lower, i.name, i.camel_name), False))
  2614.         self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
  2615.         self.c.write('%s *\n'
  2616.                      '%s_skeleton_new (void)\n'
  2617.                      '{\n'
  2618.                      '  return %s%s (g_object_new (%sTYPE_%s_SKELETON, NULL));\n'
  2619.                      '}\n'
  2620.                      '\n'%(i.camel_name, i.name_lower, i.ns_upper, i.name_upper, i.ns_upper, i.name_upper))
  2621.  
  2622.     # ---------------------------------------------------------------------------------------------------
  2623.  
  2624.     def generate_object(self):
  2625.         self.c.write('/* ------------------------------------------------------------------------\n'
  2626.                      ' * Code for Object, ObjectProxy and ObjectSkeleton\n'
  2627.                      ' * ------------------------------------------------------------------------\n'
  2628.                      ' */\n'
  2629.                      '\n')
  2630.  
  2631.         self.c.write(self.docbook_gen.expand(
  2632.                 '/**\n'
  2633.                 ' * SECTION:%sObject\n'
  2634.                 ' * @title: %sObject\n'
  2635.                 ' * @short_description: Specialized GDBusObject types\n'
  2636.                 ' *\n'
  2637.                 ' * This section contains the #%sObject, #%sObjectProxy, and #%sObjectSkeleton types which make it easier to work with objects implementing generated types for D-Bus interfaces.\n'
  2638.                 ' */\n'
  2639.                 %(self.namespace, self.namespace, self.namespace, self.namespace, self.namespace), False))
  2640.         self.c.write('\n')
  2641.  
  2642.         self.c.write(self.docbook_gen.expand(
  2643.                 '/**\n'
  2644.                 ' * %sObject:\n'
  2645.                 ' *\n'
  2646.                 ' * The #%sObject type is a specialized container of interfaces.\n'
  2647.                 ' */\n'
  2648.                 %(self.namespace, self.namespace), False))
  2649.         self.c.write('\n')
  2650.  
  2651.         self.c.write(self.docbook_gen.expand(
  2652.                 '/**\n'
  2653.                 ' * %sObjectIface:\n'
  2654.                 ' * @parent_iface: The parent interface.\n'
  2655.                 ' *\n'
  2656.                 ' * Virtual table for the #%sObject interface.\n'
  2657.                 ' */\n'
  2658.                 %(self.namespace, self.namespace), False))
  2659.         self.c.write('\n')
  2660.  
  2661.         self.c.write('typedef %sObjectIface %sObjectInterface;\n'%(self.namespace, self.namespace))
  2662.         self.c.write('G_DEFINE_INTERFACE_WITH_CODE (%sObject, %sobject, G_TYPE_OBJECT, g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_DBUS_OBJECT));\n'%(self.namespace, self.ns_lower))
  2663.         self.c.write('\n')
  2664.         self.c.write('static void\n'
  2665.                      '%sobject_default_init (%sObjectIface *iface)\n'
  2666.                      '{\n'
  2667.                      %(self.ns_lower, self.namespace));
  2668.         for i in self.ifaces:
  2669.             self.c.write(self.docbook_gen.expand(
  2670.                     '  /**\n'
  2671.                     '   * %sObject:%s:\n'
  2672.                     '   *\n'
  2673.                     '   * The #%s instance corresponding to the D-Bus interface #%s, if any.\n'
  2674.                     '   *\n'
  2675.                     '   * Connect to the #GObject::notify signal to get informed of property changes.\n'
  2676.                     %(self.namespace, i.name_hyphen, i.camel_name, i.name), False))
  2677.             self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 2)
  2678.             self.c.write('  g_object_interface_install_property (iface, g_param_spec_object ("%s", "%s", "%s", %sTYPE_%s, G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS));\n'
  2679.                          '\n'
  2680.                          %(i.name_hyphen, i.name_hyphen, i.name_hyphen, self.ns_upper, i.name_upper))
  2681.         self.c.write('}\n'
  2682.                      '\n')
  2683.  
  2684.         for i in self.ifaces:
  2685.             self.c.write(self.docbook_gen.expand(
  2686.                     '/**\n'
  2687.                     ' * %sobject_get_%s:\n'
  2688.                     ' * @object: A #%sObject.\n'
  2689.                     ' *\n'
  2690.                     ' * Gets the #%s instance for the D-Bus interface #%s on @object, if any.\n'
  2691.                     ' *\n'
  2692.                     ' * Returns: (transfer full): A #%s that must be freed with g_object_unref() or %%NULL if @object does not implement the interface.\n'
  2693.                     %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name, i.name, i.camel_name), False))
  2694.             self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
  2695.             self.c.write ('%s *%sobject_get_%s (%sObject *object)\n'
  2696.                           %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
  2697.             self.c.write('{\n'
  2698.                          '  GDBusInterface *ret;\n'
  2699.                          '  ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
  2700.                          '  if (ret == NULL)\n'
  2701.                          '    return NULL;\n'
  2702.                          '  return %s%s (ret);\n'
  2703.                          '}\n'
  2704.                          '\n'
  2705.                          %(i.name, self.ns_upper, i.name_upper))
  2706.         self.c.write('\n')
  2707.         for i in self.ifaces:
  2708.             self.c.write(self.docbook_gen.expand(
  2709.                     '/**\n'
  2710.                     ' * %sobject_peek_%s: (skip)\n'
  2711.                     ' * @object: A #%sObject.\n'
  2712.                     ' *\n'
  2713.                     ' * Like %sobject_get_%s() but doesn\'t increase the reference count on the returned object.\n'
  2714.                     ' *\n'
  2715.                     ' * <warning>It is not safe to use the returned object if you are on another thread than the one where the #GDBusObjectManagerClient or #GDBusObjectManagerServer for @object is running.</warning>\n'
  2716.                     ' *\n'
  2717.                     ' * Returns: (transfer none): A #%s or %%NULL if @object does not implement the interface. Do not free the returned object, it is owned by @object.\n'
  2718.                     %(self.ns_lower, i.name_upper.lower(), self.namespace, self.ns_lower, i.name_upper.lower(), i.camel_name), False))
  2719.             self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
  2720.             self.c.write ('%s *%sobject_peek_%s (%sObject *object)\n'
  2721.                           %(i.camel_name, self.ns_lower, i.name_upper.lower(), self.namespace))
  2722.             self.c.write('{\n'
  2723.                          '  GDBusInterface *ret;\n'
  2724.                          '  ret = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
  2725.                          '  if (ret == NULL)\n'
  2726.                          '    return NULL;\n'
  2727.                          '  g_object_unref (ret);\n'
  2728.                          '  return %s%s (ret);\n'
  2729.                          '}\n'
  2730.                          '\n'
  2731.                          %(i.name, self.ns_upper, i.name_upper))
  2732.         self.c.write('\n')
  2733.         # shared by ObjectProxy and ObjectSkeleton classes
  2734.         self.c.write('static void\n'
  2735.                      '%sobject_notify (GDBusObject *object, GDBusInterface *interface)\n'
  2736.                      '{\n'
  2737.                      '  g_object_notify (G_OBJECT (object), ((_ExtendedGDBusInterfaceInfo *) g_dbus_interface_get_info (interface))->hyphen_name);\n'
  2738.                      '}\n'
  2739.                      '\n'
  2740.                      %(self.ns_lower))
  2741.  
  2742.         self.c.write(self.docbook_gen.expand(
  2743.                 '/**\n'
  2744.                 ' * %sObjectProxy:\n'
  2745.                 ' *\n'
  2746.                 ' * The #%sObjectProxy structure contains only private data and should only be accessed using the provided API.\n'
  2747.                 %(self.namespace, self.namespace), False))
  2748.         self.c.write(' */\n')
  2749.         self.c.write('\n')
  2750.         self.c.write(self.docbook_gen.expand(
  2751.                 '/**\n'
  2752.                 ' * %sObjectProxyClass:\n'
  2753.                 ' * @parent_class: The parent class.\n'
  2754.                 ' *\n'
  2755.                 ' * Class structure for #%sObjectProxy.\n'
  2756.                 %(self.namespace, self.namespace), False))
  2757.         self.c.write(' */\n')
  2758.         self.c.write('\n')
  2759.         # class boilerplate
  2760.         self.c.write('static void\n'
  2761.                      '%sobject_proxy__%sobject_iface_init (%sObjectIface *iface G_GNUC_UNUSED)\n'
  2762.                      '{\n'
  2763.                      '}\n'
  2764.                      '\n'
  2765.                      %(self.ns_lower, self.ns_lower, self.namespace))
  2766.         self.c.write('static void\n'
  2767.                      '%sobject_proxy__g_dbus_object_iface_init (GDBusObjectIface *iface)\n'
  2768.                      '{\n'
  2769.                      '  iface->interface_added = %sobject_notify;\n'
  2770.                      '  iface->interface_removed = %sobject_notify;\n'
  2771.                      '}\n'
  2772.                      '\n'
  2773.                      %(self.ns_lower, self.ns_lower, self.ns_lower))
  2774.         self.c.write('\n')
  2775.         self.c.write('G_DEFINE_TYPE_WITH_CODE (%sObjectProxy, %sobject_proxy, G_TYPE_DBUS_OBJECT_PROXY,\n'
  2776.                      '                         G_IMPLEMENT_INTERFACE (%sTYPE_OBJECT, %sobject_proxy__%sobject_iface_init)\n'
  2777.                      '                         G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %sobject_proxy__g_dbus_object_iface_init));\n'
  2778.                      '\n'
  2779.                      %(self.namespace, self.ns_lower, self.ns_upper, self.ns_lower, self.ns_lower, self.ns_lower))
  2780.         # class boilerplate
  2781.         self.c.write('static void\n'
  2782.                      '%sobject_proxy_init (%sObjectProxy *object G_GNUC_UNUSED)\n'
  2783.                      '{\n'
  2784.                      '}\n'
  2785.                      '\n'%(self.ns_lower, self.namespace))
  2786.         self.c.write('static void\n'
  2787.                      '%sobject_proxy_set_property (GObject      *gobject,\n'
  2788.                      '  guint         prop_id,\n'
  2789.                      '  const GValue *value G_GNUC_UNUSED,\n'
  2790.                      '  GParamSpec   *pspec)\n'
  2791.                      '{\n'
  2792.                      '  G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
  2793.                      %(self.ns_lower))
  2794.         self.c.write('}\n'
  2795.                      '\n'%())
  2796.         self.c.write('static void\n'
  2797.                      '%sobject_proxy_get_property (GObject      *gobject,\n'
  2798.                      '  guint         prop_id,\n'
  2799.                      '  GValue       *value,\n'
  2800.                      '  GParamSpec   *pspec)\n'
  2801.                      '{\n'
  2802.                      '  %sObjectProxy *object = %sOBJECT_PROXY (gobject);\n'
  2803.                      '  GDBusInterface *interface;\n'
  2804.                      '\n'
  2805.                      '  switch (prop_id)\n'
  2806.                      '    {\n'
  2807.                      %(self.ns_lower, self.namespace, self.ns_upper))
  2808.         n = 1
  2809.         for i in self.ifaces:
  2810.             self.c.write('    case %d:\n'
  2811.                          '      interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
  2812.                          '      g_value_take_object (value, interface);\n'
  2813.                          '      break;\n'
  2814.                          '\n'
  2815.                          %(n, i.name))
  2816.             n += 1
  2817.         self.c.write('    default:\n'
  2818.                      '      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
  2819.                      '      break;\n'
  2820.                      '  }\n'
  2821.                      '}\n'
  2822.                      '\n'%())
  2823.         self.c.write('static void\n'
  2824.                      '%sobject_proxy_class_init (%sObjectProxyClass *klass)\n'
  2825.                      '{\n'
  2826.                      '  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);\n'
  2827.                      '\n'
  2828.                      '  gobject_class->set_property = %sobject_proxy_set_property;\n'
  2829.                      '  gobject_class->get_property = %sobject_proxy_get_property;\n'
  2830.                      '\n'
  2831.                      %(self.ns_lower, self.namespace, self.ns_lower, self.ns_lower))
  2832.         n = 1
  2833.         for i in self.ifaces:
  2834.             self.c.write('  g_object_class_override_property (gobject_class, %d, "%s");'
  2835.                          '\n'
  2836.                          %(n, i.name_hyphen))
  2837.             n += 1
  2838.         self.c.write('}\n'
  2839.                      '\n')
  2840.  
  2841.         self.c.write(self.docbook_gen.expand(
  2842.                 '/**\n'
  2843.                 ' * %sobject_proxy_new:\n'
  2844.                 ' * @connection: A #GDBusConnection.\n'
  2845.                 ' * @object_path: An object path.\n'
  2846.                 ' *\n'
  2847.                 ' * Creates a new proxy object.\n'
  2848.                 ' *\n'
  2849.                 ' * Returns: (transfer full): The proxy object.\n'
  2850.                 ' */\n'
  2851.                 %(self.ns_lower), False))
  2852.         self.c.write('%sObjectProxy *\n'
  2853.                      '%sobject_proxy_new (GDBusConnection *connection,\n'
  2854.                      '  const gchar *object_path)\n'
  2855.                      '{\n'
  2856.                      '  g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);\n'
  2857.                      '  g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);\n'
  2858.                      '  return %sOBJECT_PROXY (g_object_new (%sTYPE_OBJECT_PROXY, "g-connection", connection, "g-object-path", object_path, NULL));\n'
  2859.                      '}\n'
  2860.                      '\n'%(self.namespace, self.ns_lower, self.ns_upper, self.ns_upper))
  2861.  
  2862.         self.c.write(self.docbook_gen.expand(
  2863.                 '/**\n'
  2864.                 ' * %sObjectSkeleton:\n'
  2865.                 ' *\n'
  2866.                 ' * The #%sObjectSkeleton structure contains only private data and should only be accessed using the provided API.\n'
  2867.                 %(self.namespace, self.namespace), False))
  2868.         self.c.write(' */\n')
  2869.         self.c.write('\n')
  2870.         self.c.write(self.docbook_gen.expand(
  2871.                 '/**\n'
  2872.                 ' * %sObjectSkeletonClass:\n'
  2873.                 ' * @parent_class: The parent class.\n'
  2874.                 ' *\n'
  2875.                 ' * Class structure for #%sObjectSkeleton.\n'
  2876.                 %(self.namespace, self.namespace), False))
  2877.         self.c.write(' */\n')
  2878.         self.c.write('\n')
  2879.         # class boilerplate
  2880.         self.c.write('static void\n'
  2881.                      '%sobject_skeleton__%sobject_iface_init (%sObjectIface *iface G_GNUC_UNUSED)\n'
  2882.                      '{\n'
  2883.                      '}\n'
  2884.                      '\n'
  2885.                      %(self.ns_lower, self.ns_lower, self.namespace))
  2886.         self.c.write('\n')
  2887.         self.c.write('static void\n'
  2888.                      '%sobject_skeleton__g_dbus_object_iface_init (GDBusObjectIface *iface)\n'
  2889.                      '{\n'
  2890.                      '  iface->interface_added = %sobject_notify;\n'
  2891.                      '  iface->interface_removed = %sobject_notify;\n'
  2892.                      '}\n'
  2893.                      '\n'
  2894.                      %(self.ns_lower, self.ns_lower, self.ns_lower))
  2895.         self.c.write('G_DEFINE_TYPE_WITH_CODE (%sObjectSkeleton, %sobject_skeleton, G_TYPE_DBUS_OBJECT_SKELETON,\n'
  2896.                      '                         G_IMPLEMENT_INTERFACE (%sTYPE_OBJECT, %sobject_skeleton__%sobject_iface_init)\n'
  2897.                      '                         G_IMPLEMENT_INTERFACE (G_TYPE_DBUS_OBJECT, %sobject_skeleton__g_dbus_object_iface_init));\n'
  2898.                      '\n'
  2899.                      %(self.namespace, self.ns_lower, self.ns_upper, self.ns_lower, self.ns_lower, self.ns_lower))
  2900.         # class boilerplate
  2901.         self.c.write('static void\n'
  2902.                      '%sobject_skeleton_init (%sObjectSkeleton *object G_GNUC_UNUSED)\n'
  2903.                      '{\n'
  2904.                      '}\n'
  2905.                      '\n'%(self.ns_lower, self.namespace))
  2906.         self.c.write('static void\n'
  2907.                      '%sobject_skeleton_set_property (GObject      *gobject,\n'
  2908.                      '  guint         prop_id,\n'
  2909.                      '  const GValue *value,\n'
  2910.                      '  GParamSpec   *pspec)\n'
  2911.                      '{\n'
  2912.                      '  %sObjectSkeleton *object = %sOBJECT_SKELETON (gobject);\n'
  2913.                      '  GDBusInterfaceSkeleton *interface;\n'
  2914.                      '\n'
  2915.                      '  switch (prop_id)\n'
  2916.                      '    {\n'
  2917.                      %(self.ns_lower, self.namespace, self.ns_upper))
  2918.         n = 1
  2919.         for i in self.ifaces:
  2920.             self.c.write('    case %d:\n'
  2921.                          '      interface = g_value_get_object (value);\n'
  2922.                          '      if (interface != NULL)\n'
  2923.                          '        {\n'
  2924.                          '          g_warn_if_fail (%sIS_%s (interface));\n'
  2925.                          '          g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (object), interface);\n'
  2926.                          '        }\n'
  2927.                          '      else\n'
  2928.                          '        {\n'
  2929.                          '          g_dbus_object_skeleton_remove_interface_by_name (G_DBUS_OBJECT_SKELETON (object), "%s");\n'
  2930.                          '        }\n'
  2931.                          '      break;\n'
  2932.                          '\n'
  2933.                          %(n, self.ns_upper, i.name_upper, i.name))
  2934.             n += 1
  2935.         self.c.write('    default:\n'
  2936.                      '      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
  2937.                      '      break;\n'
  2938.                      '  }\n'
  2939.                      '}\n'
  2940.                      '\n'%())
  2941.         self.c.write('static void\n'
  2942.                      '%sobject_skeleton_get_property (GObject      *gobject,\n'
  2943.                      '  guint         prop_id,\n'
  2944.                      '  GValue       *value,\n'
  2945.                      '  GParamSpec   *pspec)\n'
  2946.                      '{\n'
  2947.                      '  %sObjectSkeleton *object = %sOBJECT_SKELETON (gobject);\n'
  2948.                      '  GDBusInterface *interface;\n'
  2949.                      '\n'
  2950.                      '  switch (prop_id)\n'
  2951.                      '    {\n'
  2952.                      %(self.ns_lower, self.namespace, self.ns_upper))
  2953.         n = 1
  2954.         for i in self.ifaces:
  2955.             self.c.write('    case %d:\n'
  2956.                          '      interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), "%s");\n'
  2957.                          '      g_value_take_object (value, interface);\n'
  2958.                          '      break;\n'
  2959.                          '\n'
  2960.                          %(n, i.name))
  2961.             n += 1
  2962.         self.c.write('    default:\n'
  2963.                      '      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n'
  2964.                      '      break;\n'
  2965.                      '  }\n'
  2966.                      '}\n'
  2967.                      '\n'%())
  2968.         self.c.write('static void\n'
  2969.                      '%sobject_skeleton_class_init (%sObjectSkeletonClass *klass)\n'
  2970.                      '{\n'
  2971.                      '  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);\n'
  2972.                      '\n'
  2973.                      '  gobject_class->set_property = %sobject_skeleton_set_property;\n'
  2974.                      '  gobject_class->get_property = %sobject_skeleton_get_property;\n'
  2975.                      '\n'
  2976.                      %(self.ns_lower, self.namespace, self.ns_lower, self.ns_lower))
  2977.         n = 1
  2978.         for i in self.ifaces:
  2979.             self.c.write('  g_object_class_override_property (gobject_class, %d, "%s");'
  2980.                          '\n'
  2981.                          %(n, i.name_hyphen))
  2982.             n += 1
  2983.         self.c.write('}\n'
  2984.                      '\n')
  2985.         self.c.write(self.docbook_gen.expand(
  2986.                 '/**\n'
  2987.                 ' * %sobject_skeleton_new:\n'
  2988.                 ' * @object_path: An object path.\n'
  2989.                 ' *\n'
  2990.                 ' * Creates a new skeleton object.\n'
  2991.                 ' *\n'
  2992.                 ' * Returns: (transfer full): The skeleton object.\n'
  2993.                 ' */\n'
  2994.                 %(self.ns_lower), False))
  2995.         self.c.write('%sObjectSkeleton *\n'
  2996.                      '%sobject_skeleton_new (const gchar *object_path)\n'
  2997.                      '{\n'
  2998.                      '  g_return_val_if_fail (g_variant_is_object_path (object_path), NULL);\n'
  2999.                      '  return %sOBJECT_SKELETON (g_object_new (%sTYPE_OBJECT_SKELETON, "g-object-path", object_path, NULL));\n'
  3000.                      '}\n'
  3001.                      '\n'%(self.namespace, self.ns_lower, self.ns_upper, self.ns_upper))
  3002.         for i in self.ifaces:
  3003.             self.c.write(self.docbook_gen.expand(
  3004.                     '/**\n'
  3005.                     ' * %sobject_skeleton_set_%s:\n'
  3006.                     ' * @object: A #%sObjectSkeleton.\n'
  3007.                     ' * @interface_: (allow-none): A #%s or %%NULL to clear the interface.\n'
  3008.                     ' *\n'
  3009.                     ' * Sets the #%s instance for the D-Bus interface #%s on @object.\n'
  3010.                     %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name, i.camel_name, i.name), False))
  3011.             self.write_gtkdoc_deprecated_and_since_and_close(i, self.c, 0)
  3012.             self.c.write ('void %sobject_skeleton_set_%s (%sObjectSkeleton *object, %s *interface_)\n'
  3013.                           %(self.ns_lower, i.name_upper.lower(), self.namespace, i.camel_name))
  3014.             self.c.write('{\n'
  3015.                          '  g_object_set (G_OBJECT (object), "%s", interface_, NULL);\n'
  3016.                          '}\n'
  3017.                          '\n'
  3018.                          %(i.name_hyphen))
  3019.         self.c.write('\n')
  3020.  
  3021.  
  3022.     def generate_object_manager_client(self):
  3023.         self.c.write('/* ------------------------------------------------------------------------\n'
  3024.                      ' * Code for ObjectManager client\n'
  3025.                      ' * ------------------------------------------------------------------------\n'
  3026.                      ' */\n'
  3027.                      '\n')
  3028.  
  3029.         self.c.write(self.docbook_gen.expand(
  3030.                 '/**\n'
  3031.                 ' * SECTION:%sObjectManagerClient\n'
  3032.                 ' * @title: %sObjectManagerClient\n'
  3033.                 ' * @short_description: Generated GDBusObjectManagerClient type\n'
  3034.                 ' *\n'
  3035.                 ' * This section contains a #GDBusObjectManagerClient that uses %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc.\n'
  3036.                 ' */\n'
  3037.                 %(self.namespace, self.namespace, self.ns_lower), False))
  3038.         self.c.write('\n')
  3039.  
  3040.         self.c.write(self.docbook_gen.expand(
  3041.                 '/**\n'
  3042.                 ' * %sObjectManagerClient:\n'
  3043.                 ' *\n'
  3044.                 ' * The #%sObjectManagerClient structure contains only private data and should only be accessed using the provided API.\n'
  3045.                 %(self.namespace, self.namespace), False))
  3046.         self.c.write(' */\n')
  3047.         self.c.write('\n')
  3048.  
  3049.         self.c.write(self.docbook_gen.expand(
  3050.                 '/**\n'
  3051.                 ' * %sObjectManagerClientClass:\n'
  3052.                 ' * @parent_class: The parent class.\n'
  3053.                 ' *\n'
  3054.                 ' * Class structure for #%sObjectManagerClient.\n'
  3055.                 %(self.namespace, self.namespace), False))
  3056.         self.c.write(' */\n')
  3057.         self.c.write('\n')
  3058.  
  3059.         # class boilerplate
  3060.         self.c.write('G_DEFINE_TYPE (%sObjectManagerClient, %sobject_manager_client, G_TYPE_DBUS_OBJECT_MANAGER_CLIENT);\n'
  3061.                      '\n'
  3062.                      %(self.namespace, self.ns_lower))
  3063.  
  3064.         # class boilerplate
  3065.         self.c.write('static void\n'
  3066.                      '%sobject_manager_client_init (%sObjectManagerClient *manager G_GNUC_UNUSED)\n'
  3067.                      '{\n'
  3068.                      '}\n'
  3069.                      '\n'%(self.ns_lower, self.namespace))
  3070.         self.c.write('static void\n'
  3071.                      '%sobject_manager_client_class_init (%sObjectManagerClientClass *klass G_GNUC_UNUSED)\n'
  3072.                      '{\n'
  3073.                      '}\n'
  3074.                      '\n'%(self.ns_lower, self.namespace))
  3075.  
  3076.         self.c.write(self.docbook_gen.expand(
  3077.                 '/**\n'
  3078.                 ' * %sobject_manager_client_get_proxy_type:\n'
  3079.                 ' * @manager: A #GDBusObjectManagerClient.\n'
  3080.                 ' * @object_path: The object path of the remote object (unused).\n'
  3081.                 ' * @interface_name: (allow-none): Interface name of the remote object or %%NULL to get the object proxy #GType.\n'
  3082.                 ' * @user_data: User data (unused).\n'
  3083.                 ' *\n'
  3084.                 ' * A #GDBusProxyTypeFunc that maps @interface_name to the generated #GDBusObjectProxy<!-- -->- and #GDBusProxy<!-- -->-derived types.\n'
  3085.                 ' *\n'
  3086.                 ' * Returns: A #GDBusProxy<!-- -->-derived #GType if @interface_name is not %%NULL, otherwise the #GType for #%sObjectProxy.\n'
  3087.                 %(self.ns_lower, self.namespace), False))
  3088.         self.c.write(' */\n')
  3089.         self.c.write('GType\n'
  3090.                      '%sobject_manager_client_get_proxy_type (GDBusObjectManagerClient *manager G_GNUC_UNUSED, const gchar *object_path G_GNUC_UNUSED, const gchar *interface_name, gpointer user_data G_GNUC_UNUSED)\n'
  3091.                      '{\n'
  3092.                      %(self.ns_lower))
  3093.         self.c.write('  static gsize once_init_value = 0;\n'
  3094.                      '  static GHashTable *lookup_hash;\n'
  3095.                      '  GType ret;\n'
  3096.                      '\n'
  3097.                      '  if (interface_name == NULL)\n'
  3098.                      '    return %sTYPE_OBJECT_PROXY;\n'
  3099.                      '  if (g_once_init_enter (&once_init_value))\n'
  3100.                      '    {\n'
  3101.                      '      lookup_hash = g_hash_table_new (g_str_hash, g_str_equal);\n'
  3102.                      %(self.ns_upper))
  3103.         for i in self.ifaces:
  3104.             self.c.write('      g_hash_table_insert (lookup_hash, (gpointer) "%s", GSIZE_TO_POINTER (%sTYPE_%s_PROXY));\n'
  3105.                          %(i.name, i.ns_upper, i.name_upper))
  3106.         self.c.write('      g_once_init_leave (&once_init_value, 1);\n'
  3107.                      '    }\n')
  3108.         self.c.write('  ret = (GType) GPOINTER_TO_SIZE (g_hash_table_lookup (lookup_hash, interface_name));\n'
  3109.                      '  if (ret == (GType) 0)\n'
  3110.                      '    ret = G_TYPE_DBUS_PROXY;\n')
  3111.         self.c.write('  return ret;\n'
  3112.                      '}\n'
  3113.                      '\n')
  3114.  
  3115.         # constructors
  3116.         self.c.write(self.docbook_gen.expand(
  3117.                 '/**\n'
  3118.                 ' * %sobject_manager_client_new:\n'
  3119.                 ' * @connection: A #GDBusConnection.\n'
  3120.                 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
  3121.                 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
  3122.                 ' * @object_path: An object path.\n'
  3123.                 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
  3124.                 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
  3125.                 ' * @user_data: User data to pass to @callback.\n'
  3126.                 ' *\n'
  3127.                 ' * Asynchronously creates #GDBusObjectManagerClient using %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. See g_dbus_object_manager_client_new() for more details.\n'
  3128.                 ' *\n'
  3129.                 ' * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.\n'
  3130.                 ' * You can then call %sobject_manager_client_new_finish() to get the result of the operation.\n'
  3131.                 ' *\n'
  3132.                 ' * See %sobject_manager_client_new_sync() for the synchronous, blocking version of this constructor.\n'
  3133.                 %(self.ns_lower, self.ns_lower, self.ns_lower, self.ns_lower), False))
  3134.         self.c.write(' */\n')
  3135.         self.c.write('void\n'
  3136.                      '%sobject_manager_client_new (\n'
  3137.                      '    GDBusConnection        *connection,\n'
  3138.                      '    GDBusObjectManagerClientFlags  flags,\n'
  3139.                      '    const gchar            *name,\n'
  3140.                      '    const gchar            *object_path,\n'
  3141.                      '    GCancellable           *cancellable,\n'
  3142.                      '    GAsyncReadyCallback     callback,\n'
  3143.                      '    gpointer                user_data)\n'
  3144.                      '{\n'
  3145.                      '  g_async_initable_new_async (%sTYPE_OBJECT_MANAGER_CLIENT, G_PRIORITY_DEFAULT, cancellable, callback, user_data, "flags", flags, "name", name, "connection", connection, "object-path", object_path, "get-proxy-type-func", %sobject_manager_client_get_proxy_type, NULL);\n'
  3146.                      '}\n'
  3147.                      '\n'
  3148.                      %(self.ns_lower, self.ns_upper, self.ns_lower))
  3149.         self.c.write('/**\n'
  3150.                      ' * %sobject_manager_client_new_finish:\n'
  3151.                      ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %sobject_manager_client_new().\n'
  3152.                      ' * @error: Return location for error or %%NULL\n'
  3153.                      ' *\n'
  3154.                      ' * Finishes an operation started with %sobject_manager_client_new().\n'
  3155.                      ' *\n'
  3156.                      ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
  3157.                      %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace))
  3158.         self.c.write(' */\n')
  3159.         self.c.write('GDBusObjectManager *\n'
  3160.                      '%sobject_manager_client_new_finish (\n'
  3161.                      '    GAsyncResult        *res,\n'
  3162.                      '    GError             **error)\n'
  3163.                      '{\n'
  3164.                      '  GObject *ret;\n'
  3165.                      '  GObject *source_object;\n'
  3166.                      '  source_object = g_async_result_get_source_object (res);\n'
  3167.                      '  ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
  3168.                      '  g_object_unref (source_object);\n'
  3169.                      '  if (ret != NULL)\n'
  3170.                      '    return G_DBUS_OBJECT_MANAGER (ret);\n'
  3171.                      '  else\n'
  3172.                      '    return NULL;\n'
  3173.                      '}\n'
  3174.                      '\n'
  3175.                      %(self.ns_lower))
  3176.         self.c.write(self.docbook_gen.expand(
  3177.                 '/**\n'
  3178.                 ' * %sobject_manager_client_new_sync:\n'
  3179.                 ' * @connection: A #GDBusConnection.\n'
  3180.                 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
  3181.                 ' * @name: (allow-none): A bus name (well-known or unique) or %%NULL if @connection is not a message bus connection.\n'
  3182.                 ' * @object_path: An object path.\n'
  3183.                 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
  3184.                 ' * @error: Return location for error or %%NULL\n'
  3185.                 ' *\n'
  3186.                 ' * Synchronously creates #GDBusObjectManagerClient using %sobject_manager_client_get_proxy_type() as the #GDBusProxyTypeFunc. See g_dbus_object_manager_client_new_sync() for more details.\n'
  3187.                 ' *\n'
  3188.                 ' * The calling thread is blocked until a reply is received.\n'
  3189.                 ' *\n'
  3190.                 ' * See %sobject_manager_client_new() for the asynchronous version of this constructor.\n'
  3191.                 ' *\n'
  3192.                 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
  3193.                 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace), False))
  3194.         self.c.write(' */\n')
  3195.         self.c.write('GDBusObjectManager *\n'
  3196.                      '%sobject_manager_client_new_sync (\n'
  3197.                      '    GDBusConnection        *connection,\n'
  3198.                      '    GDBusObjectManagerClientFlags  flags,\n'
  3199.                      '    const gchar            *name,\n'
  3200.                      '    const gchar            *object_path,\n'
  3201.                      '    GCancellable           *cancellable,\n'
  3202.                      '    GError                **error)\n'
  3203.                      '{\n'
  3204.                      '  GInitable *ret;\n'
  3205.                      '  ret = g_initable_new (%sTYPE_OBJECT_MANAGER_CLIENT, cancellable, error, "flags", flags, "name", name, "connection", connection, "object-path", object_path, "get-proxy-type-func", %sobject_manager_client_get_proxy_type, NULL);\n'
  3206.                      '  if (ret != NULL)\n'
  3207.                      '    return G_DBUS_OBJECT_MANAGER (ret);\n'
  3208.                      '  else\n'
  3209.                      '    return NULL;\n'
  3210.                      '}\n'
  3211.                      '\n'
  3212.                      %(self.ns_lower, self.ns_upper, self.ns_lower))
  3213.         self.c.write('\n')
  3214.         self.c.write(self.docbook_gen.expand(
  3215.                 '/**\n'
  3216.                 ' * %sobject_manager_client_new_for_bus:\n'
  3217.                 ' * @bus_type: A #GBusType.\n'
  3218.                 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
  3219.                 ' * @name: A bus name (well-known or unique).\n'
  3220.                 ' * @object_path: An object path.\n'
  3221.                 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
  3222.                 ' * @callback: A #GAsyncReadyCallback to call when the request is satisfied.\n'
  3223.                 ' * @user_data: User data to pass to @callback.\n'
  3224.                 ' *\n'
  3225.                 ' * Like %sobject_manager_client_new() but takes a #GBusType instead of a #GDBusConnection.\n'
  3226.                 ' *\n'
  3227.                 ' * When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.\n'
  3228.                 ' * You can then call %sobject_manager_client_new_for_bus_finish() to get the result of the operation.\n'
  3229.                 ' *\n'
  3230.                 ' * See %sobject_manager_client_new_for_bus_sync() for the synchronous, blocking version of this constructor.\n'
  3231.                 %(self.ns_lower, self.ns_lower, self.ns_lower, self.ns_lower), False))
  3232.         self.c.write(' */\n')
  3233.         self.c.write('void\n'
  3234.                      '%sobject_manager_client_new_for_bus (\n'
  3235.                      '    GBusType                bus_type,\n'
  3236.                      '    GDBusObjectManagerClientFlags  flags,\n'
  3237.                      '    const gchar            *name,\n'
  3238.                      '    const gchar            *object_path,\n'
  3239.                      '    GCancellable           *cancellable,\n'
  3240.                      '    GAsyncReadyCallback     callback,\n'
  3241.                      '    gpointer                user_data)\n'
  3242.                      '{\n'
  3243.                      '  g_async_initable_new_async (%sTYPE_OBJECT_MANAGER_CLIENT, G_PRIORITY_DEFAULT, cancellable, callback, user_data, "flags", flags, "name", name, "bus-type", bus_type, "object-path", object_path, "get-proxy-type-func", %sobject_manager_client_get_proxy_type, NULL);\n'
  3244.                      '}\n'
  3245.                      '\n'
  3246.                      %(self.ns_lower, self.ns_upper, self.ns_lower))
  3247.         self.c.write('/**\n'
  3248.                      ' * %sobject_manager_client_new_for_bus_finish:\n'
  3249.                      ' * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to %sobject_manager_client_new_for_bus().\n'
  3250.                      ' * @error: Return location for error or %%NULL\n'
  3251.                      ' *\n'
  3252.                      ' * Finishes an operation started with %sobject_manager_client_new_for_bus().\n'
  3253.                      ' *\n'
  3254.                      ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
  3255.                      %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace))
  3256.         self.c.write(' */\n')
  3257.         self.c.write('GDBusObjectManager *\n'
  3258.                      '%sobject_manager_client_new_for_bus_finish (\n'
  3259.                      '    GAsyncResult        *res,\n'
  3260.                      '    GError             **error)\n'
  3261.                      '{\n'
  3262.                      '  GObject *ret;\n'
  3263.                      '  GObject *source_object;\n'
  3264.                      '  source_object = g_async_result_get_source_object (res);\n'
  3265.                      '  ret = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error);\n'
  3266.                      '  g_object_unref (source_object);\n'
  3267.                      '  if (ret != NULL)\n'
  3268.                      '    return G_DBUS_OBJECT_MANAGER (ret);\n'
  3269.                      '  else\n'
  3270.                      '    return NULL;\n'
  3271.                      '}\n'
  3272.                      '\n'
  3273.                      %(self.ns_lower))
  3274.         self.c.write(self.docbook_gen.expand(
  3275.                 '/**\n'
  3276.                 ' * %sobject_manager_client_new_for_bus_sync:\n'
  3277.                 ' * @bus_type: A #GBusType.\n'
  3278.                 ' * @flags: Flags from the #GDBusObjectManagerClientFlags enumeration.\n'
  3279.                 ' * @name: A bus name (well-known or unique).\n'
  3280.                 ' * @object_path: An object path.\n'
  3281.                 ' * @cancellable: (allow-none): A #GCancellable or %%NULL.\n'
  3282.                 ' * @error: Return location for error or %%NULL\n'
  3283.                 ' *\n'
  3284.                 ' * Like %sobject_manager_client_new_sync() but takes a #GBusType instead of a #GDBusConnection.\n'
  3285.                 ' *\n'
  3286.                 ' * The calling thread is blocked until a reply is received.\n'
  3287.                 ' *\n'
  3288.                 ' * See %sobject_manager_client_new_for_bus() for the asynchronous version of this constructor.\n'
  3289.                 ' *\n'
  3290.                 ' * Returns: (transfer full) (type %sObjectManagerClient): The constructed object manager client or %%NULL if @error is set.\n'
  3291.                 %(self.ns_lower, self.ns_lower, self.ns_lower, self.namespace), False))
  3292.         self.c.write(' */\n')
  3293.         self.c.write('GDBusObjectManager *\n'
  3294.                      '%sobject_manager_client_new_for_bus_sync (\n'
  3295.                      '    GBusType                bus_type,\n'
  3296.                      '    GDBusObjectManagerClientFlags  flags,\n'
  3297.                      '    const gchar            *name,\n'
  3298.                      '    const gchar            *object_path,\n'
  3299.                      '    GCancellable           *cancellable,\n'
  3300.                      '    GError                **error)\n'
  3301.                      '{\n'
  3302.                      '  GInitable *ret;\n'
  3303.                      '  ret = g_initable_new (%sTYPE_OBJECT_MANAGER_CLIENT, cancellable, error, "flags", flags, "name", name, "bus-type", bus_type, "object-path", object_path, "get-proxy-type-func", %sobject_manager_client_get_proxy_type, NULL);\n'
  3304.                      '  if (ret != NULL)\n'
  3305.                      '    return G_DBUS_OBJECT_MANAGER (ret);\n'
  3306.                      '  else\n'
  3307.                      '    return NULL;\n'
  3308.                      '}\n'
  3309.                      '\n'
  3310.                      %(self.ns_lower, self.ns_upper, self.ns_lower))
  3311.         self.c.write('\n')
  3312.  
  3313.     # ---------------------------------------------------------------------------------------------------
  3314.  
  3315.     def write_gtkdoc_deprecated_and_since_and_close(self, obj, f, indent):
  3316.         if len(obj.since) > 0:
  3317.             f.write('%*s *\n'
  3318.                     '%*s * Since: %s\n'
  3319.                     %(indent, '', indent, '', obj.since))
  3320.         if obj.deprecated:
  3321.             if isinstance(obj, dbustypes.Interface):
  3322.                 thing = 'The D-Bus interface'
  3323.             elif isinstance(obj, dbustypes.Method):
  3324.                 thing = 'The D-Bus method'
  3325.             elif isinstance(obj, dbustypes.Signal):
  3326.                 thing = 'The D-Bus signal'
  3327.             elif isinstance(obj, dbustypes.Property):
  3328.                 thing = 'The D-Bus property'
  3329.             else:
  3330.                 raise RuntimeError('Cannot handle object ', obj)
  3331.             f.write(self.docbook_gen.expand(
  3332.                     '%*s *\n'
  3333.                     '%*s * Deprecated: %s has been deprecated.\n'
  3334.                     %(indent, '', indent, '', thing), False))
  3335.         f.write('%*s */\n'%(indent, ''))
  3336.  
  3337.     # ---------------------------------------------------------------------------------------------------
  3338.  
  3339.     def generate_interface_intro(self, i):
  3340.         self.c.write('/* ------------------------------------------------------------------------\n'
  3341.                      ' * Code for interface %s\n'
  3342.                      ' * ------------------------------------------------------------------------\n'
  3343.                      ' */\n'
  3344.                      '\n'%(i.name))
  3345.  
  3346.         self.c.write(self.docbook_gen.expand(
  3347.                 '/**\n'
  3348.                 ' * SECTION:%s\n'
  3349.                 ' * @title: %s\n'
  3350.                 ' * @short_description: Generated C code for the %s D-Bus interface\n'
  3351.                 ' *\n'
  3352.                 ' * This section contains code for working with the #%s D-Bus interface in C.\n'
  3353.                 ' */\n'
  3354.                 %(i.camel_name, i.camel_name, i.name, i.name), False))
  3355.         self.c.write('\n')
  3356.  
  3357.     def generate(self):
  3358.         self.generate_intro()
  3359.         self.declare_types()
  3360.         for i in self.ifaces:
  3361.             self.generate_interface_intro(i)
  3362.             self.generate_introspection_for_interface(i)
  3363.             self.generate_interface(i)
  3364.             self.generate_property_accessors(i)
  3365.             self.generate_signal_emitters(i)
  3366.             self.generate_method_calls(i)
  3367.             self.generate_method_completers(i)
  3368.             self.generate_proxy(i)
  3369.             self.generate_skeleton(i)
  3370.         if self.generate_objmanager:
  3371.             self.generate_object()
  3372.             self.generate_object_manager_client()
  3373.         self.generate_outro()
  3374.